Imports Crystal.DatabaseManagement.BusinessLayer
Imports System.Text.RegularExpressions
Imports System.Xml.Linq
Imports CrystalCommon.View
Imports Crystal.CLL
Imports Infragistics.Win
Imports System.Configuration

Public Class frmAddModifyInvestor

#Region "Declare"
    Private InvestorIds As String = String.Empty
    Dim OldInvestorName As String = String.Empty
    Dim NewInvestorName As String = String.Empty
    Dim IsSelectedChanged As Boolean = True
    Dim oneString As String = "1"
    Private _NullField As String = "--------"
    Private _NullID As Integer = -8
    Private UltimateInPriInv = -5
    '----------------------------------------------------------------------------------------------
    Public mdtNewInvestorDetails As DataTable = Nothing
    Public mlstInvestorDetails As List(Of AddNewInvestor)
    Public mintProjectID As Integer = 0
    Public mintRowNumber As Integer
    Public mdtNewFunds As DataTable = Nothing
    Public mblnIsEditInDataHub As Boolean = False
    Public mblnCancelDataHub As Boolean = False
    '-----------------------------------------------------------t-----------------------------------
    Private mstrScreenName As String = "Add Edit Investor"
    Dim isCurrentlySaved As Boolean = False
    Dim CreatednewInvestor As Boolean = False
    Public invID As String
    Private savingprocess As Boolean = False
    Private tabid As Integer
    Delegate Sub ShowDetailDelegate()
    Private _EntId As String
    Private objInvester As BusinessLayer.cAddModifyInvestor
    Private _InvId As Integer
    Private _countryname As String
    Public Event AddParticularInvestorInGrid(ByVal InvestorId As Integer)
    Public Event CloseUserWindow(ByVal InvestorID As Integer)
    Private _blnNLE As Boolean
    Public m_ModifyingInvestor As Integer
    Public m_htModifyingInvestor As Hashtable = Nothing
    Private m_strOriginalSuperholder As String
    Private m_strOldInvestorName As String
    Private regEmail As ValidationManager.RegularExpressionValidator
    Dim isInsertProcess As Boolean = False
    Dim preUltimateParent As String = String.Empty
    Dim IsLoading As Boolean = False
    Dim isFilling As Boolean = False
    Dim istypeChanged As Boolean = False
    Dim isCountryChanged As Boolean = False
    Public mdtLinkedFunds As DataTable = Nothing
    Private _IsDetailChanged As Boolean = True
    Private _IsInvFundLinked As Boolean = False
    Private _IsUltimateParentChage As Boolean = False
    Private _IsProperInvestor As Boolean
    Private _PerDataTable As DataTable = CreateDT()
    Public CheckValueChange = False
#End Region

#Region "Properties"

    Public Property InvestorId() As Integer
        Get
            Return _InvId
        End Get
        Set(ByVal value As Integer)
            _InvId = value
        End Set
    End Property

    Private Property EntId() As String
        Get
            Return _EntId
        End Get
        Set(ByVal value As String)
            _EntId = value
        End Set
    End Property

#End Region

#Region "Constructor"
    Public Sub New()
        InitializeComponent()
        GetValidatedControls()
        DisableRightClickInTextBox()
        SetConfiguration()
    End Sub
#End Region

#Region "Form events"

    Private Sub frmAddModifyInvestor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lblEntityID.Visible = False
        llblWebsite.Visible = False
        lblInvestorID.Focus()
        Dim delgate As ShowDetailDelegate = Nothing
        Try
            If (InvestorId <> 0) Then
                lblInvestorID.Text = InvestorId
                Dim Dt As DataSet = Nothing
                Dt = cAddModifyInvestor.GetEntityIDByInvestorID(InvestorId)
                If Dt IsNot Nothing Then
                    If Dt.Tables(0).Rows.Count > 0 Then
                        If Dt.Tables(0).Rows(0)(0).ToString() = String.Empty Then
                            mblnCancelDataHub = True
                            Me.Close()
                        Else
                            lblInvestorID.Text = Dt.Tables(0).Rows(0)(0).ToString()
                        End If
                    Else
                        mblnCancelDataHub = True
                        Me.Close()
                        Exit Sub
                    End If
                End If
                Dt = cAddModifyInvestor.GetFundsByInvID(InvestorId)
                If Dt.Tables(0).Rows.Count <> 0 Then
                    grdInvestors.DataSource = Dt.Tables(0)
                Else
                    grdInvestors.DataSource = CreateDT()
                End If
                llblWebsite.Visible = True
                With grdInvestors
                    If .DisplayLayout.Bands(0).Columns.Exists("FundID") Then
                        .DisplayLayout.Bands(0).Columns("FundID").Hidden = True
                    End If
                End With
            Else
                SetPropertiesNewInvestor()
                grdInvestors.DataSource = CreateDT()
                HideDefaultColumn()
            End If
            Me.grdInvestors.DisplayLayout.Override.CellClickAction = CellClickAction.CellSelect
            _InvId = InvestorId
            EntId = ""
            If (InvestorId <> 0) Then cmbState.Enabled = False
            delgate = New ShowDetailDelegate(AddressOf FormLoad)
            Me.BeginInvoke(delgate)
            Application.DoEvents()
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        Finally
        End Try
    End Sub
    Private Sub HideDefaultColumn()
        With grdInvestors
            If .DisplayLayout.Bands(0).Columns.Exists("FundID") Then
                .DisplayLayout.Bands(0).Columns("FundID").Hidden = True
            End If
        End With
    End Sub
    Private Sub SetPropertiesNewInvestor()
        rdDelete.Enabled = False
        rdDormant.Enabled = False
        rdExtinct.Enabled = False
        rdActive.Checked = True
        lblInvestorID.Visible = False
    End Sub
    Private Sub frmAddModifyInvestor_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            If isCurrentlySaved = False Then
                If (InvestorId <> 0) Then
                    If (CheckRecordExistence("investor", InvestorId) = False) Then
                        MessageBox.Show("Record you are trying to modify/delete either does not exists or deleted by some other user", m_strMsgBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
                        Exit Sub
                    End If
                End If
                If (savingprocess) Then
                    If (MessageBox.Show("Any changes will not be saved, do you really want to exit?", m_strMsgBoxCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.No) Then
                        e.Cancel = True
                        Exit Sub
                    End If
                End If
                If (InvestorId <> 0) Then
                    If (checkcontentsChange() = True) Or _IsInvFundLinked Then
                        If (MessageBox.Show("Do you wish to save?", mstrMsgBoxCaption, MessageBoxButtons.OKCancel, MessageBoxIcon.Information) = Windows.Forms.DialogResult.OK) Then
                            If IsValid() Then
                                e.Cancel = True
                                Exit Sub
                            End If
                            If IsEmptyControl() Then
                                e.Cancel = True
                                Exit Sub
                            Else
                                If (OverView_update_insert(False) = False) Then
                                    e.Cancel = True
                                    Exit Sub
                                End If
                            End If
                        End If

                    End If
                Else
                    If (cmbMasterInvestorType.SelectedIndex <> m_strSelectIDValue Or cmbTurnoverLabel.SelectedIndex <> m_strSelectIDValue Or _
                        cmbStyle.SelectedIndex <> m_strSelectIDValue Or cmbCity.SelectedIndex <> m_strSelectIDValue Or _IsInvFundLinked Or cmbCountry.SelectedIndex <> m_strSelectIDValue Or txtInvestorName.Text.Trim <> "") Then

                        If (MessageBox.Show("Do you wish to save?", mstrMsgBoxCaption, MessageBoxButtons.OKCancel, MessageBoxIcon.Information) = Windows.Forms.DialogResult.OK) Then
                            If IsValid() Then
                                e.Cancel = True
                                Exit Sub
                                'Return
                            End If
                            If IsEmptyControl() Then
                                e.Cancel = True
                                Exit Sub
                            Else
                                If (OverView_update_insert(False) = False) Then
                                    e.Cancel = True
                                    Exit Sub
                                End If
                            End If

                        End If
                    End If
                End If
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            'frmaddModifyInv = Nothing
        End Try

    End Sub
    Public Function IsEmptyControl() As Boolean
        If txtCAFLocalNumber.Text = String.Empty Or txtCMobLocalNumber.Text = String.Empty Or txtCPFLocalNumber.Text = String.Empty Or txtCTelExtension.Text = String.Empty Or _
            txtCTelLocalNumber.Text = String.Empty Or txtEmail.Text = String.Empty Or txtequityAssets.Text.ToString = String.Empty Or txtExt.Text = String.Empty Or _
            txtPostalCode.Text = String.Empty Or txtStreet1.Text = String.Empty Or txtStreet2.Text = String.Empty Or txtRegion.Text = String.Empty Then
            Return True
        End If
        Return False
    End Function
    Public Sub SetControlProperties()
        Dim code As Integer = 191
        pnlInvestor.BackColor = Color.FromArgb(code, code, code)
        rdActive.BackColor = Color.FromArgb(code, code, code)
        rdDelete.BackColor = Color.FromArgb(code, code, code)
        rdExtinct.BackColor = Color.FromArgb(code, code, code)
        rdDormant.BackColor = Color.FromArgb(code, code, code)
        llblWebsite.BackColor = Color.FromArgb(code, code, code)
        rdActive.ForeColor = Color.Black
        rdDelete.ForeColor = Color.Black
        rdExtinct.ForeColor = Color.Black
        rdDormant.ForeColor = Color.Black
    End Sub


#End Region

#Region "Check the existence of Investor"

    Private Function CheckInvexistecnce() As Boolean
        If (InvestorId <> 0) Then
            If (CheckRecordExistence("investor", InvestorId) = False) Then
                ShowMessage(MessageManager.GetMessage("INVESTORDELETED"))
                Return False
            End If
        End If
        Return True
    End Function

#End Region

#Region "Placing the Investor Name at the top of Ultimate parent and parent dropdown"

    ''' <summary>
    ''' Sending the investor at top in ultimate parent
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub ChangeTopOrderOfUltimateParent()
        Dim DtParent As DataTable = Nothing
        Dim DrParent() As DataRow
        Dim Datarow As DataRow
        Try
            DtParent = cmbUltimateParent.DataSource
            DrParent = DtParent.Select("Ultimateparent='" + txtInvestorName.Text.Trim() + "'")
            If (DrParent.Length = 0) Then
                Datarow = DtParent.NewRow
                Datarow("Ultimateparent") = txtInvestorName.Text.Trim()
                Datarow("UltimateparentId") = "-3"
                DtParent.Rows.InsertAt(Datarow, 1)
            Else
                Datarow = DtParent.NewRow
                Datarow("Ultimateparent") = txtInvestorName.Text.Trim()
                Datarow("UltimateparentId") = DrParent(0)("UltimateparentId")
                DtParent.Rows.Remove(DrParent(0))
                DtParent.Rows.InsertAt(Datarow, 1)
            End If
            cmbUltimateParent.DataSource = DtParent
        Catch ex As Exception
        Finally
            DtParent = Nothing
            DrParent = Nothing
            Datarow = Nothing
        End Try
    End Sub

    ''' <summary>
    ''' Sending the investor at top in parent
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub ChangeTopOrderOfParent()
        Dim DtParent As DataTable = Nothing
        Dim DrParent() As DataRow
        Dim Datarow As DataRow
        Try
            DtParent = cmbParent.DataSource
            DrParent = DtParent.Select("[parent]='" + txtInvestorName.Text.Trim() + "'")
            If (DrParent.Length = 0) Then
                Datarow = DtParent.NewRow
                Datarow("parent") = txtInvestorName.Text.Trim()
                Datarow("parentId") = "-3"
                DtParent.Rows.InsertAt(Datarow, 1)
            Else
                Datarow = DtParent.NewRow
                Datarow("parent") = txtInvestorName.Text.Trim()
                Datarow("parentId") = DrParent(0)("parentId")
                DtParent.Rows.Remove(DrParent(0))
                DtParent.Rows.InsertAt(Datarow, 1)
            End If
            cmbParent.DataSource = DtParent
        Catch ex As Exception
        Finally
            DtParent = Nothing
            DrParent = Nothing
            Datarow = Nothing
        End Try
    End Sub

#End Region

#Region "Load Investor Detail"
    Private Function CreateDT()
        Dim clone As DataTable = Nothing
        Try
            clone = New DataTable
            clone.Columns.Add("FundID", GetType(Integer))
            clone.Columns.Add("FundName", GetType(String))

            Return clone
        Catch ex As Exception
            If (Not Me.IsDisposed) Then
                MessageBox.Show(ex.Message)
            End If
            Return Nothing
        Finally
            clone = Nothing
        End Try
    End Function

    Private Sub LoadInvestorDetails()
        Dim objPopulateOverview As New BusinessLayer.cAddModifyInvestor
        Dim dr As DataRow
        Dim DataTable As DataTable
        Dim ds As New DataSet
        Dim IDR As IDataReader = Nothing
        Dim s(12) As String
        Try
            IsSelectedChanged = False
            IsLoading = True
            IDR = cAddModifyInvestor.GetOverViewDataSet()
            ds.Load(IDR, LoadOption.OverwriteChanges, s)
            mdlCommon.ChangeDataReaderDataSet(ds)

            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            '''''''''cmbCountry'''''''''''''''''''''
            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            If InvestorId = 0 Then
                isCountryChanged = True
            End If
            cmbCountry.DisplayMember = "CountryName"
            cmbCountry.ValueMember = "CountryID"
            DataTable = ds.Tables(0)
            cmbCountry.DataSource = DataTable
            If DropDownAtFirst(DataTable, cmbCountry.ValueMember, cmbCountry.DisplayMember, m_strNewIDValue, m_strNewTextValue) = False Then
                mdlCommon.ShowMessage("Error in accessing Country drop down.", MessageBoxIcons.Error)
                Exit Sub
            End If

            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            'combo Countnry for Additional Detail
            cmbCountryAD.DisplayMember = "CountryName"
            cmbCountryAD.ValueMember = "CountryID"
            cmbCountryAD.DataSource = DataTable
            isCountryChanged = False

            ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            'cmbStyle dupinder Singh
            cmbStyle.DisplayMember = "style"
            cmbStyle.ValueMember = "styleid"
            DataTable = ds.Tables(1)
            cmbStyle.DataSource = DataTable
            If DropDownAtFirst(DataTable, cmbStyle.ValueMember, cmbStyle.DisplayMember, m_strNewIDValue, m_strNewTextValue) = False Then
                mdlCommon.ShowMessage("Error in accessing Style drop down.", MessageBoxIcons.Error)
                Exit Sub
            End If

            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            'cmbTurnover
            cmbTurnoverLabel.DisplayMember = "Turnover"
            cmbTurnoverLabel.ValueMember = "TurnoverID"
            DataTable = ds.Tables(2)
            cmbTurnoverLabel.DataSource = DataTable

            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            cmbInvestorType.DisplayMember = "Sub Investor Type"
            cmbInvestorType.ValueMember = "InvestorTypeID"
            DataTable = ds.Tables(3)
            If InvestorId = 0 Then
                istypeChanged = True
            End If
            cmbInvestorType.DataSource = DataTable
            If DropDownAtFirst(DataTable, cmbInvestorType.ValueMember, cmbInvestorType.DisplayMember, m_strNewIDValue, m_strNewTextValue) = False Then
                mdlCommon.ShowMessage("Error in accessing Investor Type drop down.", MessageBoxIcons.Error)
                Exit Sub
            End If
            istypeChanged = False

            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

            cmbHeadInvestor.DisplayMember = "Head Investor"
            cmbHeadInvestor.ValueMember = "HeadInvestorID"
            DataTable = ds.Tables(4)
            cmbHeadInvestor.DataSource = DataTable
            If DropDownAtFirst(DataTable, cmbHeadInvestor.ValueMember, cmbHeadInvestor.DisplayMember, m_strNewIDValue, m_strNewTextValue) = False Then
                mdlCommon.ShowMessage("Error in accessing Header Investor drop down.", MessageBoxIcons.Error)
                Exit Sub
            End If


            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

            cmbParent.DisplayMember = "Parent"
            cmbParent.ValueMember = "ParentID"
            DataTable = ds.Tables(5)
            cmbParent.DataSource = DataTable
            If DropDownAtFirst(DataTable, cmbParent.ValueMember, cmbParent.DisplayMember, m_strNewIDValue, m_strNewTextValue) = False Then
                mdlCommon.ShowMessage("Error in accessing Parent Investor drop down.", MessageBoxIcons.Error)
                Exit Sub
            End If
            'PArent

            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

            'cmbUltimate Parent
            cmbUltimateParent.DisplayMember = "UltimateParent"
            cmbUltimateParent.ValueMember = "UltimateParentID"
            DataTable = ds.Tables(6)
            cmbUltimateParent.DataSource = DataTable
            If DropDownAtFirst(DataTable, cmbUltimateParent.ValueMember, cmbUltimateParent.DisplayMember, m_strNewIDValue, m_strNewTextValue) = False Then
                mdlCommon.ShowMessage("Error in accessing Ultimate Parent drop down.", MessageBoxIcons.Error)
                Exit Sub
            End If

            '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

            cmbActivist.DisplayMember = "Activist"
            cmbActivist.ValueMember = "ActivistID"
            DataTable = ds.Tables(7)
            cmbActivist.DataSource = DataTable
            If DropDownAtFirst(DataTable, cmbActivist.ValueMember, cmbActivist.DisplayMember, m_strNewIDValue, m_strNewTextValue) = False Then
                mdlCommon.ShowMessage("Error in accessing Ultimate Parent drop down.", MessageBoxIcons.Error)
                Exit Sub
            End If
            If InvestorId = 0 Then
                cmbCountry.SelectedValue = m_strSelectIDValue
                cmbActivist.SelectedValue = m_strSelectIDValue
                cmbUltimateParent.SelectedValue = m_strSelectIDValue
                cmbParent.SelectedValue = m_strSelectIDValue
                cmbInvestorType.SelectedValue = m_strSelectIDValue
                cmbHeadInvestor.SelectedValue = m_strSelectIDValue
                cmbStyle.SelectedValue = m_strSelectIDValue
                'cmbState.SelectedValue = m_strSelectIDValue
                cmbCountryAD.SelectedValue = m_strSelectIDValue
                'cmbCity.SelectedValue = m_strSelectIDValue
                cmbTurnoverLabel.SelectedValue = m_strSelectIDValue
                dtLastReport.Text = String.Empty
            End If
            IsSelectedChanged = True
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            dr = Nothing
            DataTable = Nothing
            objPopulateOverview = Nothing
            ds = Nothing
            IsLoading = False
        End Try
    End Sub

#End Region

#Region "Fill Controls"

    Private Sub FillControls()
        Dim objcAddModifyInvestor As BusinessLayer.cAddModifyInvestor = Nothing
        Dim datatable As New DataTable
        Dim MasterInvestorTypeId As Integer = 0
        Dim IDR As IDataReader = Nothing
        Try
            Call LoadInvestorDetails()
            _countryname = ""
            If (InvestorId = 0) Then
                ClearAll()
                Return

            End If
            objcAddModifyInvestor = New BusinessLayer.cAddModifyInvestor
            IDR = objcAddModifyInvestor.ShowOverviewData(InvestorId)
            datatable.Load(IDR)
            mdlCommon.ChangeDataReaderDataTable(datatable)
            If (datatable.Rows.Count = 0) Then
                TrackForOldInvestorNewInvestor("", "")
                Exit Sub
            End If
            For i As Integer = 0 To datatable.Rows.Count - 1
                If (IsDBNull(datatable.Rows(i).Item("InvestorName")) = False) Then
                    txtInvestorName.Text = datatable.Rows(i).Item("InvestorName").ToString().Trim()
                Else
                    txtInvestorName.Text = txtInvestorName.Text
                End If



                If (IsDBNull(datatable.Rows(i).Item("HeadInvestorID")) = False) Then
                    UpdateHeadInvestor(txtInvestorName.Text)
                    UpdateUltimatePrincipalInvestor(txtInvestorName.Text)
                    cmbHeadInvestor.SelectedValue = datatable.Rows(i).Item("HeadInvestorID").ToString()
                    If (cmbHeadInvestor.SelectedValue Is Nothing) Then
                        cmbHeadInvestor.SelectedIndex = m_strSelectIDValue
                    End If
                Else
                    If InvestorId <> 0 Then
                        UpdateHeadInvestor(txtInvestorName.Text)
                        UpdateUltimatePrincipalInvestor(txtInvestorName.Text)
                    End If
                    'cmbHeadInvestor.SelectedIndex = m_strSelectIDValue
                End If

                If (IsDBNull(datatable.Rows(i).Item("UltimateParentID")) = False) Then
                    cmbUltimateParent.SelectedValue = datatable.Rows(i).Item("UltimateParentID").ToString()
                    If (cmbUltimateParent.SelectedValue Is Nothing) Then
                        cmbUltimateParent.SelectedIndex = m_strSelectIDValue
                    End If
                Else
                    cmbUltimateParent.SelectedIndex = m_strSelectIDValue
                End If

                If (IsDBNull(datatable.Rows(i).Item("ParentID")) = False) Then
                    cmbParent.SelectedValue = datatable.Rows(i).Item("ParentID").ToString()
                    If (cmbParent.SelectedValue Is Nothing) Then
                        cmbParent.SelectedIndex = m_strSelectIDValue
                    End If
                Else
                    cmbParent.SelectedIndex = m_strSelectIDValue
                End If



                If (IsDBNull(datatable.Rows(i).Item("ActivistID")) = False) Then
                    cmbActivist.SelectedValue = datatable.Rows(i).Item("ActivistID").ToString()
                    If (cmbActivist.SelectedValue Is Nothing) Then
                        cmbActivist.SelectedIndex = m_strSelectIDValue
                    End If
                Else
                    cmbActivist.SelectedIndex = m_strSelectIDValue
                End If

                If (IsDBNull(datatable.Rows(i).Item("InvestorTypeID")) = False) Then
                    cmbInvestorType.SelectedValue = datatable.Rows(i).Item("InvestorTypeID").ToString()
                    If (cmbInvestorType.SelectedValue Is Nothing) Then
                        cmbInvestorType.SelectedIndex = m_strSelectIDValue
                    End If
                Else
                    cmbInvestorType.SelectedIndex = m_strSelectIDValue
                End If

                If (IsDBNull(datatable.Rows(i).Item("MInvestorTypeID")) = False) Then
                    'If cmbMasterInvestorType.SelectedValue 
                    '/cmbMasterInvestorType.SelectedValue = datatable.Rows(i).Item("MInvestorTypeID").ToString()
                    If (cmbMasterInvestorType.SelectedValue Is Nothing) Then

                        cmbMasterInvestorType.SelectedIndex = m_strSelectIDValue
                    End If
                Else
                    cmbMasterInvestorType.SelectedIndex = m_strSelectIDValue
                End If
                If (IsDBNull(datatable.Rows(i).Item("StyleID")) = False) Then
                    cmbStyle.SelectedValue = datatable.Rows(i).Item("StyleID").ToString()
                    If (cmbStyle.SelectedValue Is Nothing) Then
                        cmbStyle.SelectedIndex = 0
                    End If
                    Dim d As DataRowView = cmbStyle.SelectedItem
                    Dim str As String = d.Row.ItemArray.GetValue(0)
                    If (cmbStyle.Text = " ") Then
                        For ij As Integer = 0 To cmbStyle.Items.Count - 1
                            d = cmbStyle.Items(ij)
                            If (d.Row.Item("Style").ToString().ToLower = "na") Then
                                cmbStyle.SelectedIndex = ij
                                Exit For
                            End If
                        Next
                    End If
                Else
                    cmbStyle.SelectedIndex = 0
                End If
                If (IsDBNull(datatable.Rows(i).Item("TurnoverID")) = False) Then
                    SetIndex(cmbTurnoverLabel, datatable.Rows(i).Item("TurnoverID").ToString().Trim(), "TurnoverID")
                    If (cmbTurnoverLabel.SelectedValue Is Nothing) Then
                        cmbTurnoverLabel.SelectedIndex = m_strSelectIDValue
                    End If
                    'If (cmbTurnoverLabel.Text.ToLower = "na") Then
                    '    cmbTurnoverLabel.SelectedIndex = m_strSelectIDValue
                    'End If
                Else
                    cmbTurnoverLabel.SelectedIndex = m_strSelectIDValue
                End If

                'If (IsDBNull(datatable.Rows(i).Item("StateID")) = False) Then
                '    _countryname = datatable.Rows(i).Item("StateID").ToString()
                '    cmbState.SelectedValue = datatable.Rows(i).Item("StateID").ToString()
                '    If (cmbState.SelectedValue Is Nothing) Then
                '        cmbState.SelectedIndex = m_strSelectIDValue
                '    End If
                'Else
                '    cmbState.SelectedIndex = m_strSelectIDValue
                'End If
                If (IsDBNull(datatable.Rows(i).Item("CountryID")) = False) Then
                    cmbCountry.SelectedValue = datatable.Rows(i).Item("CountryID").ToString()
                    If (cmbCountry.SelectedValue Is Nothing) Then
                        cmbCountry.SelectedIndex = m_strSelectIDValue
                    End If
                    If (cmbCountry.Text.ToLower().Contains("united states") = True) Then
                        If (datatable.Rows(i).Item("StateID") Is DBNull.Value) Then
                            cmbState.SelectedIndex = m_strSelectIDValue
                        Else
                            cmbState.SelectedValue = datatable.Rows(i).Item("StateID").ToString()
                        End If
                    Else
                        cmbState.SelectedIndex = m_strSelectIDValue
                    End If
                Else
                    cmbCountry.SelectedIndex = m_strSelectIDValue
                End If
                If (IsDBNull(datatable.Rows(i).Item("CityID")) = False) Then
                    SetIndex(cmbCity, datatable.Rows(i).Item("CityID").ToString().Trim(), "CityID")
                    If (cmbCity.SelectedValue Is Nothing) Then
                        cmbCity.SelectedIndex = m_strSelectIDValue
                    End If
                Else
                    cmbCity.SelectedIndex = m_strSelectIDValue
                End If
                If (IsDBNull(datatable.Rows(i).Item("InvEntityID")) = False) Then
                    lblEntityID.Text = datatable.Rows(i).Item("InvEntityID").ToString().Trim()
                    EntId = lblEntityID.Text
                Else
                    EntId = ""
                End If

                If (IsDBNull(datatable.Rows(i).Item("Street1")) = False) Then
                    txtStreet1.Text = datatable.Rows(i).Item("Street1").ToString().Trim()
                End If

                If (IsDBNull(datatable.Rows(i).Item("Street2")) = False) Then
                    txtStreet2.Text = datatable.Rows(i).Item("Street2").ToString().Trim()
                End If

                If (IsDBNull(datatable.Rows(i).Item("PostalCode")) = False) Then
                    txtPostalCode.Text = datatable.Rows(i).Item("PostalCode").ToString().Trim()
                End If

                If (IsDBNull(datatable.Rows(i).Item("EmailAddress")) = False) Then
                    txtEmail.Text = datatable.Rows(i).Item("EmailAddress").ToString().Trim()
                End If

                If (IsDBNull(datatable.Rows(i).Item("FaxNumber1")) = False) Then
                    txtCPFLocalNumber.Text = datatable.Rows(i).Item("FaxNumber1").ToString().Trim()
                End If

                If (IsDBNull(datatable.Rows(i).Item("FaxNumber2")) = False) Then
                    txtCAFLocalNumber.Text = datatable.Rows(i).Item("FaxNumber2").ToString().Trim()
                End If

                If (IsDBNull(datatable.Rows(i).Item("MPhoneNumber")) = False) Then
                    txtCMobLocalNumber.Text = datatable.Rows(i).Item("MPhoneNumber").ToString().Trim()
                End If
                If (IsDBNull(datatable.Rows(i).Item("TPhoneNumber")) = False) Then
                    txtCTelLocalNumber.Text = datatable.Rows(i).Item("TPhoneNumber").ToString().Trim()
                End If

                If (IsDBNull(datatable.Rows(i).Item("TExtension")) = False) Then
                    txtExt.Text = datatable.Rows(i).Item("TExtension").ToString().Trim()
                End If

                If (IsDBNull(datatable.Rows(i).Item("EquityAssets")) = False) Then
                    txtequityAssets.Text = datatable.Rows(i).Item("EquityAssets").ToString().Trim()
                End If
                If (IsDBNull(datatable.Rows(i).Item("Website")) = False) Then
                    llblWebsite.Text = datatable.Rows(i).Item("Website").ToString().Trim()
                End If
                If (IsDBNull(datatable.Rows(i).Item("LastReportDate")) = False) Then
                    dtLastReport.Value = datatable.Rows(i).Item("LastReportDate").ToString().Trim()
                    If dtLastReport.Value = "01/01/2001" Then
                        dtLastReport.Value = ""
                    End If
                End If
                If (IsDBNull(datatable.Rows(i).Item("EStatusID")) = False) Then
                    If (EntityStatus.ACTVE = datatable.Rows(i).Item("EStatusID").ToString().Trim()) Then
                        rdActive.Checked = True
                    ElseIf (EntityStatus.DELTE = datatable.Rows(i).Item("EStatusID").ToString().Trim()) Then
                        rdDelete.Checked = True
                    ElseIf (EntityStatus.DRMNT = datatable.Rows(i).Item("EStatusID").ToString().Trim()) Then
                        rdDormant.Checked = True
                    ElseIf (EntityStatus.EXTNT = datatable.Rows(i).Item("EStatusID").ToString().Trim()) Then
                        rdExtinct.Checked = True
                    End If
                End If
            Next
            If InvestorId <> 0 Then
                m_strOldInvestorName = txtInvestorName.Text.Trim
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            objcAddModifyInvestor = Nothing
            datatable = Nothing
        End Try
    End Sub

#End Region

#Region "Places the row for ---select--- , ---others--- "

    Private Function DropDownAtFirst(ByRef dataTable As DataTable, ByVal idColumn As String, ByVal valueColumn As String, ByVal rowValue As Integer, ByVal rowText As String) As Boolean
        If dataTable Is Nothing Then Return True
        Dim drDataRow As DataRow
        drDataRow = dataTable.NewRow
        drDataRow.Item(idColumn) = rowValue
        drDataRow.Item(valueColumn) = rowText
        dataTable.Rows.InsertAt(drDataRow, 0)
        Return True
    End Function
    Private Function DropDownAtSecond(ByRef dataTable As DataTable, ByVal idColumn As String, ByVal valueColumn As String, ByVal rowValue As Integer, ByVal rowText As String) As Boolean
        If dataTable Is Nothing Then Return True
        Dim drDataRow As DataRow
        drDataRow = dataTable.NewRow
        drDataRow.Item(idColumn) = rowValue
        drDataRow.Item(valueColumn) = rowText
        dataTable.Rows.InsertAt(drDataRow, 1)
        Return True
    End Function
    Private Function DropDownAtThird(ByRef dataTable As DataTable, ByVal idColumn As String, ByVal valueColumn As String, ByVal rowValue As Integer, ByVal rowText As String) As Boolean
        If dataTable Is Nothing Then Return True
        Dim drDataRow As DataRow
        drDataRow = dataTable.NewRow
        drDataRow.Item(idColumn) = rowValue
        drDataRow.Item(valueColumn) = rowText
        dataTable.Rows.InsertAt(drDataRow, 2)
        Return True
    End Function
    Private Function DropDownAtLast(ByRef dataTable As DataTable, ByVal idColumn As String, ByVal valueColumn As String, ByVal rowValue As Integer, ByVal rowText As String) As Boolean
        If dataTable Is Nothing Then Return True
        Dim drDataRow As DataRow
        drDataRow = dataTable.NewRow
        drDataRow.Item(idColumn) = rowValue
        drDataRow.Item(valueColumn) = rowText
        dataTable.Rows.Add(drDataRow)
        Return True
    End Function

#End Region

#Region "Clear the contents of tabs"


    Private Sub ClearAll()
        Try
            txtInvestorName.Text = ""
            cmbMasterInvestorType.SelectedIndex = 0
            cmbInvestorType.SelectedIndex = 0
            cmbCity.SelectedIndex = 0
            cmbState.SelectedIndex = 0
            cmbCountry.SelectedIndex = 0
            cmbStyle.SelectedIndex = 0
            cmbTurnoverLabel.SelectedIndex = 0
            lblEntityID.Text = ""
            EntId = ""
            InvestorId = 0
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub

#End Region

#Region "Vaidations"

    ''' <summary>
    ''' For overview tab
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function ValidationForOverview() As Boolean
        Try
            If (CheckInvexistecnce() = False) Then
                DisableAllButtons(False, New Control() {txtInvestorName, cmbMasterInvestorType, cmbInvestorType, _
                  cmbStyle, cmbTurnoverLabel, cmbState, cmbCity, cmbState, cmbCountry, _
                   btnSaveInv, btnExit})
                DisableAllButtons(True, New Control() {btnExit})
                Return False
            End If

            If txtInvestorName.Text.Trim() = "" Then
                ShowMessage("Please enter the 'Investor name'.")
                txtInvestorName.Focus()
                Return False
            End If
            If (IsNumeric(txtInvestorName.Text.Trim)) Then
                ShowMessage("Please enter valid 'Investor name'.")
                txtInvestorName.Focus()
                Return False
            End If

            If cmbHeadInvestor.SelectedIndex = m_strSelectIDValue Then
                ShowMessage("Please select the 'HeadInvestor' field.")
                cmbHeadInvestor.Focus()
                Return False
            End If

            If cmbInvestorType.SelectedIndex = m_strSelectIDValue Then
                ShowMessage("Please select the 'Type' field.")
                cmbInvestorType.Focus()
                Return False
            End If

            If cmbStyle.SelectedIndex = m_strSelectIDValue Then
                ShowMessage("Please select the 'Style' field.")
                cmbStyle.Focus()
                Return False
            End If

            If cmbTurnoverLabel.SelectedIndex = m_strSelectIDValue Then
                ShowMessage("Please select the 'Turnover' field.")
                cmbTurnoverLabel.Focus()
                Return False
            End If

            If cmbCountry.SelectedIndex = m_strSelectIDValue Then
                ShowMessage("Please select the 'Country' field.")
                cmbCountry.Focus()
                Return False
            End If

            If cmbMasterInvestorType.SelectedIndex = m_strSelectIDValue Then
                ShowMessage("Please select the 'Master Investor Type' field.")
                cmbMasterInvestorType.Focus()
                Return False
            End If
            If txtequityAssets.Text.ToString.Length > 0 Then
                If Not IsNumeric(txtequityAssets.Text.Trim) Then
                    ShowMessage("Please enter valid 'Equity Assets'.")
                    txtequityAssets.Focus()
                    Return False
                End If
            End If

            If cmbCity.SelectedIndex = m_strSelectIDValue Then
                ShowMessage("Please select the 'City' field.")
                cmbCity.Focus()
                Return False
            End If

            If cmbState.SelectedIndex = m_strSelectIDValue Then
                If (cmbCountry.Text.ToLower().Contains("united states") = True) Then
                    ShowMessage("Please select the 'State' field.")
                    cmbState.Focus()
                    Return False
                End If
            End If
            'If cmbState.SelectedIndex <> 0 And IsNumeric(cmbState.Text.Trim) Then
            '    ShowMessage("Please select valid 'State' field. State name cannot be numeric.")
            '    cmbState.Focus()
            '    Return False
            'End If

            ' End If
            If (cmbCountry.Text.ToLower().Contains("united states") = True And cmbState.SelectedValue = mdlCommon.m_strBlankIdValue) Then
                For i As Integer = 0 To cmbState.Items.Count - 1
                    Dim drowas As DataRowView = cmbState.Items(i)
                    If (drowas.Item("state").ToString().ToLower() = "na") Then
                        cmbState.SelectedIndex = i
                        Exit For
                    End If
                Next
                cmbState.Focus()
                ShowMessage("Please select the 'state' field.")
                Return False
            End If
            'If (cmbState.SelectedIndex <> 0 And cmbState.SelectedIndex <> cmbState.Items.Count - 1 And cmbState.Enabled = True And cmbState.Text <> m_strSelectTextValue) Then
            '    If (cmbState.Text.Length <> 2) Then
            '        ShowMessage("Please enter the 'state' field length equal to 2.")
            '        cmbState.Focus()
            '        Return False
            '    End If
            'End If
            If (txtRegion.Text.Trim() = "") Then
                ShowMessage("Please enter the 'Region' field.")
                txtRegion.Focus()
                Return False
            End If
            'If (cmbMasterInvestorType.SelectedIndex <> 0) Then
            '    If (CheckRecordExistence("Master Investor Type", cmbMasterInvestorType.SelectedValue.ToString) = False) Then
            '        MessageBox.Show(MessageManager.GetMessage("RECORDNOTEXISTS"), m_strMsgBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
            '        Return False
            '    End If
            'End If
            'If (cmbInvestorType.SelectedIndex <> 0) Then
            '    If cmbInvestorType.SelectedValue Is Nothing Then
            '        ShowMessage("Please select the 'Sub Investor Type' field.")
            '        cmbInvestorType.Focus()
            '        Return False
            '    End If
            '    If (CheckRecordExistence("Sub Investor Type", cmbInvestorType.SelectedValue.ToString()) = False) Then
            '        MessageBox.Show("Sub Investor Type you are trying to modify/delete either does not exists or deleted by some other user", m_strMsgBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
            '        Return False
            '    End If
            'End If
            'If (cmbCity.SelectedIndex <> 0) Then
            '    If (CheckRecordExistence("City", cmbCity.SelectedValue.ToString()) = False) Then
            '        MessageBox.Show("City you are trying to modify/delete either does not exists or deleted by some other user", m_strMsgBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
            '        Return False
            '    End If
            'End If

            'If (cmbStyle.SelectedIndex <> 0) Then
            '    If (CheckRecordExistence("Style", cmbStyle.SelectedValue.ToString()) = False) Then
            '        MessageBox.Show("Style you are trying to modify/delete either does not exists or deleted by some other user", m_strMsgBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
            '        Return False
            '    End If
            'End If
            ''dupinder
            ''If (cmbTurnoverLabel.SelectedIndex <> 0) Then
            ''    If (CheckRecordExistence("Turnover", cmbTurnoverLabel.SelectedValue.ToString()) = False) Then
            ''        MessageBox.Show("Turnover you are trying to modify/delete either does not exists or deleted by some other user", m_strMsgBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
            ''        Return False
            ''    End If
            ''End If
            'If (cmbCountry.SelectedIndex <> 0) Then
            '    If (CheckRecordExistence("Country", cmbCountry.SelectedValue.ToString()) = False) Then
            '        MessageBox.Show("Country you are trying to modify/delete either does not exists or deleted by some other user", m_strMsgBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
            '        Return False
            '    End If
            'End If

            Return True
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Function

    ''' <summary>
    ''' For detail Tab
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function ValidationFordetailsTab() As Boolean
        Try
            If (CheckInvexistecnce() = False) Then Return False
            If cmbUltimateParent.SelectedIndex = 0 Then
                ShowMessage("Please select the 'Ultimate Parent' field.")
                cmbUltimateParent.Focus()
                Return False
            End If

            If cmbParent.SelectedIndex = 0 Then
                ShowMessage("Please select the 'Parent' field.")
                cmbParent.Focus()
                Return False
            End If

            If txtRegion.Text.Trim() = "" Then 'And cmbregion.Items.Count = 0 Then
                ShowMessage("Please enter the 'Region' field.")
                txtRegion.Focus()
                Return False
            End If

            If (txtCAFLocalNumber.Text.Trim() <> "") Then
                If (IsNumeric(txtCAFLocalNumber.Text.Trim()) = False) Then
                    ShowMessage("Please enter the correct 'local number' for Alternate fax")
                    txtCAFLocalNumber.Focus()
                    Return False
                End If
            End If

            If (IsNumeric(txtCPFLocalNumber.Text.Trim()) = False) Then
                ShowMessage("Please enter the correct 'local number' for Primary fax")
                txtCPFLocalNumber.Focus()
                Return False
            End If

            If (IsNumeric(txtCMobLocalNumber.Text.Trim()) = False) Then
                ShowMessage("Please enter the correct 'local number' for Mobile")
                txtCMobLocalNumber.Focus()
                Return False
            End If

            If (IsNumeric(txtCTelLocalNumber.Text.Trim()) = False) Then
                ShowMessage("Please enter the correct 'local number' for Telephone")
                txtCTelLocalNumber.Focus()
                Return False
            End If
            If (txtCTelExtension.Text.Trim() <> "") Then
                If (IsNumeric(txtCTelExtension.Text.Trim()) = False) Then
                    ShowMessage("Please enter the correct 'Extention' field.")
                    txtCTelExtension.Focus()
                    Return False
                End If
            End If
            If (txtEmail.Text.Trim() <> "") Then
                If (Validations.CheckEmail(txtEmail.Text.Trim()) = False) Then
                    ShowMessage("Please enter the correct 'Email address' field.")
                    txtEmail.Focus()
                    Return False
                End If
            End If
            If (cmbUltimateParent.SelectedIndex <> 0) Then
                If (cmbUltimateParent.SelectedIndex <> 1) Then
                    If (CheckRecordExistence("Ultimate Parent", cmbUltimateParent.SelectedValue.ToString) = False) Then
                        MessageBox.Show("Ultimate Parent you are trying to modify/delete either does not exists or deleted by some other user", m_strMsgBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
                        Return False
                    End If
                End If

            End If
            If (cmbParent.SelectedIndex <> 0) Then
                If (cmbParent.SelectedIndex <> 1) Then
                    If (CheckRecordExistence("Parent", cmbParent.SelectedValue.ToString) = False) Then
                        MessageBox.Show("Parent you are trying to modify/delete either does not exists or deleted by some other user", m_strMsgBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
                        Return False
                    End If
                End If
            End If
            Return True
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally

        End Try
    End Function

#End Region

#Region "save/Update"

    ''' <summary>
    ''' For overview tab
    ''' </summary>
    ''' <param name="saveandclose"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function OverView_update_insert(ByVal saveandclose As Boolean) As Boolean
        Dim ds As DataSet = Nothing
        Dim objInv As cAddModifyInvestor = Nothing
        Dim UltimateParentId As Integer = 0
        Dim newid As Boolean = False
        Dim Dt As DataSet = Nothing
        Dim lclsValidateInvestor As ValidateInvestor = Nothing
        Try
            ' If (ValidationForOverview() = False) Then Return False
            If _IsDetailChanged = True Then
                If (InvestorId = 0) Then
                    If txtInvestorName.Text = String.Empty Then
                        Return False
                    End If

                    Dt = cAddModifyInvestor.GetInvestorNameCount(txtInvestorName.Text)
                    If Convert.ToInt32(Dt.Tables(0).Rows(0)(0).ToString()) <> 0 Then
                        ShowMessage("Investor name already exist.")
                        Return False
                    End If
                Else
                    Dt = cAddModifyInvestor.GetInvestorNameCount(txtInvestorName.Text)
                    If Dt.Tables(1).Rows.Count > 0 Then
                        If lblInvestorID.Text <> Dt.Tables(1).Rows(0)(0).ToString() Then
                            ShowMessage("Investor name already exist.")
                            Return False
                        End If
                    End If
                End If
                '''''''''''''''''''''''''''''''''''''
                'Parminder Singh, Issue: 8928, Date: 11th Jan, 2010
                'Ask for superholder change in others if it's in Modify Mode

                '''''''''''''''''''''''''''''''''''''


                Dim UltimateInvestorExists As String = cAddModifyInvestor.IsUltimateInvestorExist(txtInvestorName.Text)
                Dim obj As New cAddModifyInvestor
                If UltimateInvestorExists = "0" Then
                    If InvestorId = 0 Then
                        obj.InsertUltimateParent(txtInvestorName.Text, False)
                        obj = Nothing
                    Else
                        Dim name As String = cAddModifyInvestor.InvNameByInvID(InvestorId)
                        obj.UpdateUltimateParentByName(name, txtInvestorName.Text)
                    End If
                Else
                    ' Dim upname As DataSet = cAddModifyInvestor.GetUltimateParentDetailByInvestorID(InvestorId)
                    'GetId and set upid
                End If


                savingprocess = True
                objInvester = New BusinessLayer.cAddModifyInvestor
                objInvester.investorName = txtInvestorName.Text.Trim()
                objInvester.masterInvestorTypeid = cmbMasterInvestorType.SelectedValue
                objInvester.investorTypeid = cmbInvestorType.SelectedValue
                If (cmbStyle.Text = String.Empty) Then
                    Dim d As DataRowView = cmbStyle.SelectedItem
                    For ij As Integer = 0 To cmbStyle.Items.Count - 1
                        d = cmbStyle.Items(ij)
                        If (d.Row.Item("style").ToString().ToLower = "na") Then
                            cmbStyle.SelectedIndex = ij
                            objInvester.styleID = d.Row.Item("styleid")
                            Exit For
                        End If
                    Next
                Else
                    objInvester.styleID = cmbStyle.SelectedValue
                End If

                objInvester.cityID = cmbCity.SelectedValue.ToString().Trim()
                If (Convert.ToInt16(cmbState.SelectedValue) <= 0) Then
                    objInvester.stateID = 0
                Else
                    objInvester.stateID = cmbState.SelectedValue.ToString().Trim()
                End If
                objInvester.turnoverID = cmbTurnoverLabel.SelectedValue
                'objInvester.stateID = cmbState.SelectedValue
                If cmbActivist.SelectedValue Is Nothing Then objInvester.activistID = 0 Else objInvester.activistID = cmbActivist.SelectedValue
                Dim dataRow As DataRowView = cmbHeadInvestor.SelectedItem
                If txtInvestorName.Text = dataRow.Item(0).ToString() Then
                    objInvester.headInvestorID = 0
                ElseIf cmbHeadInvestor.SelectedValue = UltimateInPriInv Then
                    objInvester.headInvestorID = cAddModifyInvestor.GetHeadInvestorIDByName(dataRow.Item(0).ToString())
                Else
                    objInvester.headInvestorID = cmbHeadInvestor.SelectedValue
                End If
                objInvester.parentId = cmbParent.SelectedValue
                objInvester.ultimateparentId = cmbUltimateParent.SelectedValue
                objInvester.countryID = cmbCountry.SelectedValue  'txtCounty.Text.Trim()
                objInvester.mPhoneNumber = txtCMobLocalNumber.Text
                objInvester.tPhoneNumber = txtCTelLocalNumber.Text
                objInvester.tExtention = txtExt.Text
                objInvester.faxPermanent = txtCPFLocalNumber.Text
                objInvester.fax2 = txtCAFLocalNumber.Text
                objInvester.investorTypeid = cmbInvestorType.SelectedValue
                objInvester.street1 = txtStreet1.Text
                objInvester.street2 = txtStreet2.Text
                objInvester.emailAddress = txtEmail.Text
                objInvester.lastReportDate = dtLastReport.Value  '.ToString("dd - MMM - yyyy")
                If txtequityAssets.Text.Length > 0 Then
                    'Dim isLong As Boolean = False
                    Dim value As Int64
                    'value = Int64.TryParse(txtequityAssets.Text.Trim, isLong)
                    value = txtequityAssets.Text
                    objInvester.equityAssets = value
                Else
                    objInvester.equityAssets = 0
                End If
                objInvester.postalCode = txtPostalCode.Text
                Dim val As Integer
                val = Convert.ToInt16(System.Configuration.ConfigurationManager.AppSettings("DefaultSourceTypeInvestor").ToString())
                objInvester.sourceTypeID = val
                objInvester.createdDate = DateTime.Now.ToString
                objInvester.modifyDate = DateTime.Now.ToString
                objInvester.createdBy = val
                objInvester.modifyBy = val
                If (InvestorId = 0) Then
                    objInvester.isCIRInvestor = True
                Else
                    objInvester.isCIRInvestor = False
                End If

                If (InvestorId = 0) Then
                    newid = True
                    objInvester.website = String.Empty
                Else
                    CreatednewInvestor = False
                    'objInvester.website = llblWebsite.Text
                End If

                Dim va As Integer
                If rdActive.Checked Then
                    va = EntityStatus.ACTVE
                ElseIf rdDelete.Checked Then
                    va = EntityStatus.DELTE
                ElseIf rdDormant.Checked Then
                    va = EntityStatus.DRMNT
                ElseIf rdExtinct.Checked Then
                    va = EntityStatus.EXTNT
                End If
                If mintProjectID > 0 And Not mblnIsEditInDataHub Then
                    lclsValidateInvestor = New ValidateInvestor
                    lclsValidateInvestor.Text = TitleManager.GetTitle("ValidateInvestor")
                    ValidateNewInvestor()
                    lclsValidateInvestor.mdtNewInvestor = mdtNewInvestorDetails
                    lclsValidateInvestor.mintProjectID = mintProjectID
                    lclsValidateInvestor.ShowDialog()
                    If lclsValidateInvestor.mblnCheckSaved Then
                        If lclsValidateInvestor.mdtNewInvestor.Rows(0)("InvEntityID").ToString <> String.Empty Then
                            mdtNewInvestorDetails = lclsValidateInvestor.mdtNewInvestor
                            InvestorId = lclsValidateInvestor.mdtNewInvestor.Rows(0)("InvestorID")
                            InsertFundInvLinking()
                            Return True
                        End If
                    Else
                        Return False
                    End If
                End If
                ds = objInvester.Insert_Update_Overview(InvestorId, objInvester.investorName, va, objInvester.website, objInvester.headInvestorID _
                , objInvester.investorTypeid, objInvester.styleID, objInvester.turnoverID, objInvester.countryID, objInvester.postalCode, objInvester.parentId _
                , objInvester.ultimateparentId, objInvester.masterInvestorTypeid, objInvester.activistID, objInvester.lastReportDate, objInvester.equityAssets _
                , objInvester.street1, objInvester.street2, objInvester.cityID, objInvester.stateID, objInvester.mPhoneNumber, objInvester.tPhoneNumber _
                , objInvester.tExtention, objInvester.faxPermanent, objInvester.fax2, objInvester.emailAddress, objInvester.isCIRInvestor, objInvester.sourceTypeID _
                , objInvester.createdDate, objInvester.modifyDate, objInvester.createdBy, objInvester.modifyBy, mintProjectID, lblInvestorID.Text, mblnIsEditInDataHub)
                If ds IsNot Nothing Then
                    If InvestorId <> 0 Then
                        ShowMessage("Investor updated successfully.")
                    Else
                        ShowMessage("Investor saved successfully.")
                    End If
                    isCurrentlySaved = True
                    For i As Integer = 0 To ds.Tables(ds.Tables.Count - 1).Rows.Count - 1
                        If (ds.Tables(ds.Tables.Count - 1).Rows(i).Item(0).ToString().Trim().ToLower() = "investor already exists") Then
                            ShowMessage(ds.Tables(ds.Tables.Count - 1).Rows(i).Item(0).ToString().Trim())
                            Return False
                        End If
                        m_strOldInvestorName = txtInvestorName.Text.Trim
                        If (Not ds.Tables(ds.Tables.Count - 1).Rows(i).Item(1) Is System.DBNull.Value And Not ds.Tables(ds.Tables.Count - 1).Rows(i).Item(1).ToString = "") Then
                            InvestorId = ds.Tables(ds.Tables.Count - 1).Rows(i).Item(0).ToString().Trim()
                            EntId = ds.Tables(ds.Tables.Count - 1).Rows(i).Item(1).ToString().Trim()
                        End If
                        lblEntityID.Text = EntId

                        TrackForOldInvestorNewInvestor(txtInvestorName.Text.Trim, NewInvestorName)
                    Next
                    RaiseEvent AddParticularInvestorInGrid(InvestorId)
                    If (Me.IsDisposed) Then Exit Function
                End If
            End If
            If InvestorId > 0 Then
                If mdtLinkedFunds IsNot Nothing And _IsInvFundLinked = True Then
                    If mdtLinkedFunds.Rows.Count > 0 Then
                        InsertFundInvLinking()
                        If _IsDetailChanged = False Then
                            ShowMessage("Investor updated successfully.")
                        End If
                    End If
                    _IsInvFundLinked = False
                End If
            End If
            Return True

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            objInvester = Nothing
            ds = Nothing
            savingprocess = False
        End Try
    End Function

    Private Sub ValidateNewInvestor()
        Dim larrInvestors() As String = {"Select", "InvestorID", "InvEntityID", "Investor Name", "Type", "Style", "Parent", "Master Investor Type", "City", "Country"}
        Dim ldrow As DataRow
        Try
            mdtNewInvestorDetails = New DataTable
            For i As Integer = 0 To larrInvestors.Length - 1
                If larrInvestors(i) = "Select" Then
                    mdtNewInvestorDetails.Columns.Add(larrInvestors(i), GetType(Boolean))
                Else
                    mdtNewInvestorDetails.Columns.Add(larrInvestors(i))
                End If
            Next
            ldrow = mdtNewInvestorDetails.NewRow()
            ldrow("Select") = True
            ldrow("InvestorID") = DBNull.Value
            ldrow("InvEntityID") = String.Empty
            ldrow("Investor Name") = txtInvestorName.Text
            ldrow("Type") = cmbInvestorType.Text
            ldrow("Style") = cmbStyle.Text
            ldrow("Parent") = cmbParent.Text
            ldrow("Master Investor Type") = cmbMasterInvestorType.Text
            ldrow("City") = cmbCity.Text
            ldrow("Country") = cmbCountry.Text
            mdtNewInvestorDetails.Rows.Add(ldrow)
        Catch ex As Exception
            Me.FormulateAndLogError(ex, mstrScreenName, mintProjectID)
        Finally
            ldrow = Nothing
            larrInvestors = Nothing
        End Try
    End Sub

    Private Sub InsertFundInvLinking()
        Dim IdString As String = String.Empty
        If InvestorId > 0 Then
            If mdtLinkedFunds IsNot Nothing Then
                IdString = GetXMlFromDataTable(_PerDataTable, {mdtLinkedFunds.Columns("FundName").ColumnName.ToString()})
                Dim obj As New cAddModifyInvestor
                If InvestorId > 0 Then
                    obj.InsertInvestorFundLinking(InvestorId, IdString)
                End If
                obj = Nothing
                _PerDataTable = Nothing
            End If
        End If
    End Sub
#End Region

#Region "Checking the tab whether the data is changed or not"

    ''' <summary>
    ''' For tab1
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function checkcontentsChange() As Boolean
        Dim objcAddModifyInvestor As BusinessLayer.cAddModifyInvestor = Nothing
        Dim datatable As New DataTable
        Dim idr As IDataReader = Nothing
        Dim i As Integer = 0
        Try
            objcAddModifyInvestor = New BusinessLayer.cAddModifyInvestor
            idr = objcAddModifyInvestor.ShowOverviewData(InvestorId)
            datatable.Load(idr)
            ChangeDataReaderDataTable(datatable)
            If (datatable.Rows.Count = 0) Then
                Return False
            End If

            For i = 0 To datatable.Rows.Count - 1
                If (IsDBNull(datatable.Rows(i).Item("InvestorName")) = False) Then
                    If (datatable.Rows(i).Item("InvestorName").ToString().Trim() <> txtInvestorName.Text.Trim()) Then
                        Return True
                    End If
                Else
                    If (txtInvestorName.Text <> "") Then
                        Return True

                    End If
                End If

                If (IsDBNull(datatable.Rows(i).Item("HeadInvestorID")) = False) Then
                    Dim drv As DataRowView = cmbHeadInvestor.SelectedItem
                    If (drv.Row.Item("HeadInvestorID").ToString().Trim() <> datatable.Rows(i).Item("HeadInvestorID").ToString().Trim()) Then
                        If (cmbHeadInvestor.SelectedValue <> m_strSelectIDValue And cmbHeadInvestor.SelectedIndex = 0) Then
                            Return True
                        End If
                        Dim res = (From p In CType(cmbHeadInvestor.DataSource, DataTable).AsEnumerable Where p.Item("HeadInvestorID").ToString = datatable.Rows(i).Item("HeadInvestorID").ToString()).SingleOrDefault
                        If (Not res Is Nothing) Then
                            Return True
                        End If
                    End If
                Else
                    If (cmbHeadInvestor.SelectedIndex <> 0) Then
                        If cmbHeadInvestor.SelectedItem(0).ToString() <> datatable.Rows(i).Item("InvestorName") Then
                            Return True
                        End If

                    End If
                End If


                If (IsDBNull(datatable.Rows(i).Item("InvestorTypeId")) = False) Then
                    If cmbInvestorType.SelectedItem IsNot Nothing Then
                        Dim drv As DataRowView = cmbInvestorType.SelectedItem
                        If (drv.Row.Item("InvestorTypeId").ToString().Trim() <> datatable.Rows(i).Item("InvestorTypeId").ToString().Trim()) Then
                            If (cmbMasterInvestorType.SelectedIndex = 0 And cmbInvestorType.SelectedIndex = m_strSelectIDValue) Then
                                Return True
                            End If
                            'Dim res = (From p In CType(cmbInvestorType.DataSource, DataTable).AsEnumerable Where p.Item("InvestorTypeId").ToString = datatable.Rows(i).Item("InvestorTypeId").ToString()).SingleOrDefault
                            'If (Not res Is Nothing) Then
                            '    Return True
                            'End If
                        End If
                    End If

                Else
                    If (cmbInvestorType.SelectedIndex <> 0) Then
                        Return True
                    End If
                End If

                If (IsDBNull(datatable.Rows(i).Item("MInvestorTypeId")) = False) Then
                    Dim drv As DataRowView = cmbMasterInvestorType.SelectedItem
                    If (drv.Row.Item("MInvestorTypeId").ToString().Trim() <> datatable.Rows(i).Item("MInvestorTypeId").ToString().Trim()) Then
                        Return True
                        'Dim query = (From p In CType(cmbMasterInvestorType.DataSource, DataTable).AsEnumerable() _
                        '           Where p.Item("MInvestorTypeId") = datatable.Rows(i).Item("MInvestorTypeId").ToString()).SingleOrDefault
                        'If (Not query Is Nothing) Then
                        '    Return True
                        'End If

                    End If
                Else
                    If (cmbMasterInvestorType.SelectedIndex <> m_strSelectIDValue) Then
                        Return True
                    End If
                End If
                If (IsDBNull(datatable.Rows(i).Item("StyleId")) = False) Then
                    Dim drv As DataRowView = cmbStyle.SelectedItem
                    Dim style As String = ""
                    If (drv.Row.Item("StyleId").ToString().Trim() <> datatable.Rows(i).Item("StyleId").ToString().Trim()) Then
                        Return True
                    End If
                Else
                    If (cmbStyle.SelectedIndex <> 0) Then
                        Return True
                    End If
                End If
                If (IsDBNull(datatable.Rows(i).Item("TurnoverId")) = False) Then
                    Dim drv As DataRowView = cmbTurnoverLabel.SelectedItem
                    If (drv.Row.Item("TurnoverId").ToString().Trim() = BLLmdlCommon.m_strSelectIDValue) Then
                        ' Return True
                        Dim dr() As DataRow = CType(cmbTurnoverLabel.DataSource, DataTable).Select("turnoverid=" + datatable.Rows(i).Item("TurnoverId").ToString())
                        If (dr.Length > 0) Then
                            If (dr(0)("Turnover").ToString().ToLower <> "na") Then
                                'If (drv.Row.Item("TurnoverId") <> 0) Then
                                Return True
                                'End If
                            End If
                        End If

                    Else
                        Dim turnover As String = ""
                        Dim dr() As DataRow = CType(cmbTurnoverLabel.DataSource, DataTable).Select("turnoverid=" + datatable.Rows(i).Item("TurnoverId").ToString())
                        If (dr.Length > 0) Then
                            'If (dr(0)("Turnover").ToString().ToLower = "na") Then
                            '    If (drv.Row.Item("TurnoverId") <> 0) Then
                            '        Return True
                            '    End If
                            'Else
                            If (drv.Row.Item("TurnoverId").ToString().Trim() <> datatable.Rows(i).Item("TurnoverId").ToString().Trim()) Then
                                Return True
                            End If
                            '     End If
                        End If
                    End If
                Else
                    If (cmbTurnoverLabel.SelectedIndex <> 0) Then
                        Return True
                    End If
                End If


                If (IsDBNull(datatable.Rows(i).Item("CountryId")) = False) Then
                    Dim drv As DataRowView = cmbCountry.SelectedItem
                    Dim one As String = drv.Row.Item("CountryId").ToString().Trim()
                    Dim two As String = datatable.Rows(i).Item("CountryId").ToString().Trim()
                    If (one <> two) Then
                        Return True
                    End If
                Else
                    If (cmbCountry.SelectedIndex <> 0) Then
                        Return True
                    End If
                End If
                If cmbCountry.Text.ToLower().Contains("united states") Or cmbCountry.Text.ToLower().Contains("canada") Then
                    If (datatable.Rows(i).Item("StateId").ToString().Length >= 0) Then
                        Dim drv As DataRowView = cmbState.SelectedItem
                        If (drv.Row.Item("StateId").ToString().ToLower().Trim() <> datatable.Rows(i).Item("StateId").ToString().Trim()) Then
                            Return True
                        End If
                        'Else
                        '    If (cmbState.SelectedValue <> m_strSelectIDValue) Then
                        '        Return True
                        '    End If
                    End If

                End If
                If (IsDBNull(datatable.Rows(i).Item("CityId")) = False) Then
                    Dim drv As DataRowView = cmbCity.SelectedItem
                    If (drv.Row.Item("CityId").ToString().Trim() <> datatable.Rows(i).Item("CityId").ToString().Trim()) Then
                        Return True
                    End If
                Else
                    If (cmbCity.SelectedIndex <> 0) Then
                        Return True
                    End If
                End If

                If (IsDBNull(datatable.Rows(i).Item("EStatusID")) = False) Then
                    Dim va As Integer = Convert.ToInt32(datatable.Rows(i).Item("EStatusID").ToString())
                    If va = 1 Then
                        If Not rdActive.Checked Then
                            Return True
                        End If

                    ElseIf va = 2 Then
                        If Not rdDormant.Checked Then
                            Return True
                        End If

                    ElseIf va = 3 Then
                        If Not rdExtinct.Checked Then
                            Return True
                        End If

                    ElseIf va = 4 Then
                        If Not rdDelete.Checked Then
                            Return True
                        End If
                    End If
                End If

                If (IsDBNull(datatable.Rows(i).Item("UltimateParentID")) = False) Then
                    Dim drv As DataRowView = cmbUltimateParent.SelectedItem
                    If (drv.Row.Item("UltimateParentID").ToString().Trim() <> datatable.Rows(i).Item("UltimateParentID").ToString().Trim()) Then
                        Return True
                    End If
                Else
                    If (cmbUltimateParent.SelectedIndex <> m_strSelectIDValue) Then
                        Return True
                    End If
                End If

                If (IsDBNull(datatable.Rows(i).Item("ParentID")) = False) Then
                    Dim drv As DataRowView = cmbParent.SelectedItem
                    If (drv.Row.Item("ParentID").ToString().Trim() <> datatable.Rows(i).Item("ParentID").ToString().Trim()) Then
                        Return True
                    End If
                Else
                    If (cmbParent.SelectedIndex <> m_strSelectIDValue) Then
                        Return True
                    End If
                End If
                If (IsDBNull(datatable.Rows(i).Item("ActivistID")) = False) Then
                    Dim drv As DataRowView = cmbActivist.SelectedItem
                    If (drv.Row.Item("ActivistID").ToString().Trim() <> datatable.Rows(i).Item("ActivistID").ToString().Trim()) Then
                        Return True
                    End If
                Else
                    If (cmbActivist.SelectedIndex <> m_strSelectIDValue) Then
                        Return True
                    End If
                End If
                If (IsDBNull(datatable.Rows(i).Item("LastReportDate")) = False) Then
                    If dtLastReport.Value <> Nothing And dtLastReport.Value <> "1/1/2001" Then
                        If (dtLastReport.Value <> datatable.Rows(i).Item("LastReportDate")) Then
                            Return True
                        End If
                    End If

                Else
                    If (dtLastReport.Value IsNot Nothing) Then
                        Return True
                    End If
                End If
                If (IsDBNull(datatable.Rows(i).Item("Street1")) = False) Then
                    If (txtStreet1.Text <> datatable.Rows(i).Item("Street1").ToString().Trim()) Then
                        Return True
                    End If
                Else
                    If (txtStreet1.Text.Trim() <> "") Then
                        Return True
                    End If
                End If

                If (IsDBNull(datatable.Rows(i).Item("Street2")) = False) Then
                    If (txtStreet2.Text.Trim() <> datatable.Rows(i).Item("Street2").ToString().Trim()) Then
                        Return True
                    End If
                Else
                    If (txtStreet2.Text.Trim() <> "") Then
                        Return True
                    End If
                End If

                If (IsDBNull(datatable.Rows(i).Item("EmailAddress")) = False) Then
                    If (txtEmail.Text.Trim() <> datatable.Rows(i).Item("EmailAddress").ToString().Trim()) Then
                        Return True
                    End If
                Else
                    If (txtEmail.Text <> "") Then
                        Return True
                    End If
                End If

                If (IsDBNull(datatable.Rows(i).Item("FaxNumber1")) = False) Then
                    If (txtCPFLocalNumber.Text.Trim() <> datatable.Rows(i).Item("FaxNumber1").ToString().Trim()) Then
                        Return True
                    End If
                Else
                    If (txtCPFLocalNumber.Text.Trim() <> "") Then
                        Return True
                    End If
                End If

                If (IsDBNull(datatable.Rows(i).Item("FaxNumber2")) = False) Then
                    If (txtCAFLocalNumber.Text.Trim() <> datatable.Rows(i).Item("FaxNumber2").ToString().Trim()) Then
                        Return True
                    End If
                Else
                    If (txtCAFLocalNumber.Text.Trim() <> "") Then
                        Return True
                    End If
                End If
                If (IsDBNull(datatable.Rows(i).Item("TPhoneNumber")) = False) Then
                    If (txtCTelLocalNumber.Text.Trim() <> datatable.Rows(i).Item("TPhoneNumber").ToString().Trim()) Then
                        Return True
                    End If
                Else
                    If (txtCTelLocalNumber.Text.Trim() <> "") Then
                        Return True
                    End If
                End If
                If (IsDBNull(datatable.Rows(i).Item("MPhoneNumber")) = False) Then
                    If (txtCMobLocalNumber.Text.Trim() <> datatable.Rows(i).Item("MPhoneNumber").ToString().Trim()) Then
                        Return True
                    End If
                Else
                    If (txtCMobLocalNumber.Text.Trim() <> "") Then
                        Return True
                    End If
                End If
                If (IsDBNull(datatable.Rows(i).Item("PostalCode")) = False) Then
                    If (txtPostalCode.Text.Trim() <> datatable.Rows(i).Item("PostalCode").ToString().Trim()) Then
                        Return True
                    End If
                Else
                    If (txtPostalCode.Text.Trim() <> "") Then
                        Return True
                    End If
                End If
                If (IsDBNull(datatable.Rows(i).Item("EquityAssets")) = False) Then
                    If (txtequityAssets.Text.ToString.Trim() <> datatable.Rows(i).Item("EquityAssets").ToString().Trim()) Then
                        Return True
                    End If
                Else
                    If (txtequityAssets.Text.ToString <> "") Then
                        Return True
                    End If
                End If
                If (IsDBNull(datatable.Rows(i).Item("TExtension")) = False) Then
                    If (txtExt.Text.Trim() <> datatable.Rows(i).Item("TExtension").ToString().Trim()) Then
                        Return True
                    End If
                Else
                    If (txtExt.Text.Trim() <> "") Then
                        Return True
                    End If
                End If
                Return False
            Next
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            objcAddModifyInvestor = Nothing
            datatable = Nothing

        End Try
    End Function

#End Region

#Region "Detail Tab"
#Region "Restricts the user to enter only Numeric values"
    Private Sub txtCMobLocalNumber_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCMobLocalNumber.KeyPress
        Try
            If (e.KeyChar.ToString() = ".") Then
                e.Handled = True
                Return
            End If

            Dim st As String
            If Clipboard.ContainsText() Then
                st = Clipboard.GetText()
                If (Validations.CheckNumericString(st) = False) Then
                    e.Handled = True
                    Clipboard.Clear()
                Else
                    e.Handled = False
                End If
            Else
                '  e.Handled = False
                If (Validations.CheckNumeric(e.KeyChar) = False) Then
                    e.Handled = True
                Else
                    e.Handled = False
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally

        End Try
    End Sub

    Private Sub txtCTelExtension_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPostalCode.KeyPress, txtExt.KeyPress
        Try
            If (e.KeyChar.ToString() = ".") Then
                e.Handled = True
                Return
            End If

            Dim st As String
            If Clipboard.ContainsText() Then
                st = Clipboard.GetText()
                If (Validations.CheckNumericString(st) = False) Then
                    e.Handled = True
                    Clipboard.Clear()
                Else
                    e.Handled = False
                End If
            Else
                '  e.Handled = False
                If (Validations.CheckNumeric(e.KeyChar) = False) Then
                    e.Handled = True
                Else
                    e.Handled = False
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally

        End Try
    End Sub

    Private Sub txtCPFLocalNumber_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCPFLocalNumber.KeyPress
        If (e.KeyChar.ToString() = ".") Then
            e.Handled = True
            Return
        End If
        Try
            Dim st As String
            If Clipboard.ContainsText() Then
                st = Clipboard.GetText()
                If (Validations.CheckNumericString(st) = False) Then
                    e.Handled = True
                    Clipboard.Clear()
                Else
                    e.Handled = False
                End If
            Else
                '  e.Handled = False
                If (Validations.CheckNumeric(e.KeyChar) = False) Then
                    e.Handled = True
                Else
                    e.Handled = False
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally

        End Try

    End Sub

    Private Sub txtCAFLocalNumber_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCAFLocalNumber.KeyPress
        Try
            If (e.KeyChar.ToString() = ".") Then
                e.Handled = True
                Return
            End If
            Dim st As String
            If Clipboard.ContainsText() Then
                st = Clipboard.GetText()
                If (Validations.CheckNumericString(st) = False) Then
                    e.Handled = True
                    Clipboard.Clear()
                Else
                    e.Handled = False
                End If
            Else
                '  e.Handled = False
                If (Validations.CheckNumeric(e.KeyChar) = False) Then
                    e.Handled = True
                Else
                    e.Handled = False
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally

        End Try
    End Sub

    Private Sub txtCTelLocalNumber_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtCTelLocalNumber.KeyPress
        Try
            If (e.KeyChar.ToString() = ".") Then
                e.Handled = True
                Return
            End If
            Dim st As String
            If Clipboard.ContainsText() Then
                st = Clipboard.GetText()
                If (Validations.CheckNumericString(st) = False) Then
                    e.Handled = True
                    Clipboard.Clear()
                Else
                    e.Handled = False
                End If
            Else
                If (Validations.CheckNumeric(e.KeyChar) = False) Then
                    e.Handled = True
                Else
                    e.Handled = False
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally

        End Try
    End Sub

    Private Sub txtCMobCountry_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        Try
            If (e.KeyChar.ToString() = ".") Then
                e.Handled = True
                Return
            End If
            Dim st As String
            If Clipboard.ContainsText() Then
                st = Clipboard.GetText()
                If (Validations.CheckNumericString(st) = False) Then
                    e.Handled = True
                    Clipboard.Clear()
                Else
                    e.Handled = False
                End If
            Else
                '  e.Handled = False
                If (Validations.CheckNumeric(e.KeyChar) = False) Then
                    e.Handled = True
                Else
                    e.Handled = False
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally

        End Try
    End Sub

#End Region

#Region "Buttons"

    ''' <summary>
    ''' This shall enable the controls to modify the value
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>

#End Region

#End Region

#Region "Buttons"

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveInv.Click
        ValidationManager.IsButtonClick = True
        If IsValid() Then
            Return
        End If

        If InvestorId <> 0 Then
            If mdtLinkedFunds Is Nothing And _IsInvFundLinked = False Then
                _IsInvFundLinked = False

            End If
            If (checkcontentsChange() = False) Then
                _IsDetailChanged = False
                If _IsInvFundLinked = False Then
                    'Me.Close()
                    Return
                End If

            End If
        End If
        If (OverView_update_insert(False) = True) Then
            If mintProjectID > 0 Then
                If mdtNewInvestorDetails IsNot Nothing Then
                    If mdtNewInvestorDetails.Rows.Count > 0 Then
                        InvestorDetailsForDataHub()
                        isCurrentlySaved = True
                    End If
                ElseIf mblnIsEditInDataHub Then
                    GetInvestorDetailsForDatahub()
                    Me.Close()
                End If
            End If
            If lblInvestorID.Visible = False Then
                Me.Close()
            End If
        End If


    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        'If InvestorId <> 0 Then
        '    ValidationManager.IsButtonClick = True
        '    If IsValid() Then
        '        Return
        '    End If
        'End If
        mblnCancelDataHub = True
        Me.Close()
    End Sub

#End Region

#Region "Methods"
    Private Function GetCheckedStatus() As String
        Dim str As String = String.Empty
        If rdActive.Checked Then
            str = EntityStatus.ACTVE.ToString
        ElseIf rdDelete.Checked Then
            str = EntityStatus.DELTE.ToString
        ElseIf rdDormant.Checked Then
            str = EntityStatus.DRMNT.ToString
        ElseIf rdExtinct.Checked Then
            str = EntityStatus.EXTNT.ToString
        End If
        Return str
    End Function

    Private Sub InvestorDetailsForDataHub()
        Dim ldatarow As DataRow
        Dim lintInvDefaultIDs As Integer = 0
        Try
            If mdtNewInvestorDetails IsNot Nothing Then
                If mdtNewInvestorDetails.Rows.Count > 0 Then
                    'mdtNewInvestorDetails = cAddModifyInvestor.GetDataHubInvestor(InvestorId, CommonCLL.UserID, mintProjectID, True)
                    mlstInvestorDetails = cAddModifyInvestor.GetDataHubInvestor(InvestorId, CommonCLL.UserID, mintProjectID, True)
                    Exit Sub
                End If
            End If
        Catch ex As Exception
            Me.FormulateAndLogError(ex, "Add Edit Investor", mintProjectID)
        Finally
            ldatarow = Nothing
        End Try
    End Sub

    Private Sub GetInvestorDetailsForDatahub()
        mlstInvestorDetails = New List(Of AddNewInvestor) '= cAddModifyInvestor.GetDataHubInvestor(InvestorId, CommonCLL.UserID, mintProjectID, True)
        Dim lclsAddNewInvestor As New AddNewInvestor
        lclsAddNewInvestor.Activist = cmbActivist.Text
        lclsAddNewInvestor.City = cmbCity.Text
        lclsAddNewInvestor.Country = cmbCountry.Text
        lclsAddNewInvestor.InvestorID = InvestorId
        lclsAddNewInvestor.HeadInvestor = cmbHeadInvestor.Text
        lclsAddNewInvestor.ID = lblInvestorID.Text
        lclsAddNewInvestor.InvestorName = txtInvestorName.Text
        lclsAddNewInvestor.InvStatusCode = GetStatus()
        lclsAddNewInvestor.IsInvestor = True
        lclsAddNewInvestor.LinkID = 0
        lclsAddNewInvestor.Status = GetStatusValue()
        lclsAddNewInvestor.MInvestorTypeID = cmbMasterInvestorType.SelectedValue
        lclsAddNewInvestor.ProjectId = mintProjectID
        lclsAddNewInvestor.Region = txtRegion.Text
        lclsAddNewInvestor.Parent = cmbParent.Text
        lclsAddNewInvestor.State = cmbState.Text
        lclsAddNewInvestor.Style = cmbStyle.Text
        lclsAddNewInvestor.Turnover = cmbTurnoverLabel.Text
        lclsAddNewInvestor.Type = cmbInvestorType.Text
        mlstInvestorDetails.Add(lclsAddNewInvestor)
    End Sub

    Private Function GetStatus() As String
        If rdActive.Checked Then
            Return EntityStatus.ACTVE.ToString
        ElseIf rdDelete.Checked Then
            Return EntityStatus.DELTE.ToString
        ElseIf rdDormant.Checked Then
            Return EntityStatus.DRMNT.ToString
        ElseIf rdExtinct.Checked Then
            Return EntityStatus.EXTNT.ToString
        End If
        Return String.Empty
    End Function

    Private Function GetStatusValue() As String
        If rdActive.Checked Then
            Return rdActive.Text
        ElseIf rdDelete.Checked Then
            Return rdActive.Text
        ElseIf rdDormant.Checked Then
            Return rdActive.Text
        ElseIf rdExtinct.Checked Then
            Return rdActive.Text
        End If
    End Function
    Private Sub ShowMessage(ByVal message As String)
        MessageBox.Show(message, mstrMsgBoxCaption, MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Sub

    Private Sub FormLoad()
        If (InvestorId <> 0) Then
            isFilling = True
            Call FillControls()
            TrackForOldInvestorNewInvestor(txtInvestorName.Text.Trim, txtInvestorName.Text.Trim)
            isFilling = False
        Else
            TrackForOldInvestorNewInvestor("", "")
            Call LoadInvestorDetails()
            DisableIfNewLoadControls()
        End If
        'SetControlProperties()

    End Sub
    Private Sub DisableIfNewLoadControls()
        cmbState.Enabled = False
        lblFund.Visible = False
    End Sub
    Private Sub DisableRightClickInTextBox()
        DisableRightClickInfTextEditor(txtExt)
        DisableRightClickInfTextEditor(txtCMobLocalNumber)
        DisableRightClickInfTextEditor(txtCAFLocalNumber)
        DisableRightClickInfTextEditor(txtCPFLocalNumber)
        DisableRightClickInfTextEditor(txtCTelLocalNumber)
        DisableRightClickInfTextEditor(txtPostalCode)
        DisableRightClickInfTextEditor(txtEmail)
        DisableRightClickInfTextEditor(txtInvestorName)
        DisableRightClickInfTextEditor(txtRegion)
        DisableRightClickInfTextEditor(txtequityAssets)
        DisableRightClickInfTextEditor(txtStreet1)
        DisableRightClickInfTextEditor(txtStreet2)
    End Sub
    Private Sub GetValidatedControls()
        ValidateControls(cpForm.Controls, True)
        ValidateControls(CType(pnlInvestor.Controls(0), Misc.UltraPanelClientArea).Controls, True)
        'ApplyRegexValidation(txtequityAssets,ValidationManager.RegexType.Numeric,
        RangeValidator(txtequityAssets, "999999999999999", "0", lblAssets.Text)
        ApplyRegexValidation(txtExt, ValidationManager.RegexType.Numeric, "Extension")
        ' ApplyRegexValidation(txtequityAssets, ValidationManager.RegexType.Telephone, lblAssets.Text)
        ApplyRegexValidation(txtCMobLocalNumber, ValidationManager.RegexType.Telephone, "Mobile Number")
        ApplyRegexValidation(txtCAFLocalNumber, ValidationManager.RegexType.Telephone, "Fax2 Number")
        ApplyRegexValidation(txtCPFLocalNumber, ValidationManager.RegexType.Telephone, "Fax Number")
        ApplyRegexValidation(txtCTelLocalNumber, ValidationManager.RegexType.Telephone, "TelephoneNumber")
        ApplyRegexValidation(txtPostalCode, ValidationManager.RegexType.Telephone, "Postal Code")
        ApplyRegexValidation(txtEmail, ValidationManager.RegexType.Email, "Email")
    End Sub

    Private Sub SetConfiguration()
        If BLLmdlCommon.strConfiguration Is Nothing Then BLLmdlCommon.strConfiguration = CommonCLL.mstrConnectionstring
    End Sub

    Private Sub ApplyRegexEmailValidation()
        Me.regEmail = New ValidationManager.RegularExpressionValidator()
        Me.regEmail.ControlToValidate = Me.txtEmail
        Me.regEmail.IsRequired = False
        Me.regEmail.ValidationExpression = ValidationManager.regexString(ValidationManager.RegexType.Email)
        Me.regEmail.ErrorMessage = ShowErrorMessage(DBResult.INVALID, BaseClass.Capitalize("Email"))
    End Sub

    Private Function IsValid() As Boolean
        If Not (Me.ValidateChildren()) Then
            ValidationManager.IsButtonClick = False
            'FocusOnEmptyControl()
            Return True
        End If
        ValidationManager.IsButtonClick = False
        Return False
    End Function

#End Region

#Region "Acquire/Merge Transaction"

#Region "Log details"

    Private Sub TrackForOldInvestorNewInvestor(ByVal newInv As String, ByVal OldInv As String)
        NewInvestorName = newInv
        OldInvestorName = OldInv
    End Sub

#End Region

#End Region

#Region "Combo selected value changed"
    Dim cntrl As Control

    Private Function GetFocusedControl(ByVal Controls As System.Windows.Forms.Control.ControlCollection) As System.Windows.Forms.Control
        ' store focused control... 
        For Each clsControl As System.Windows.Forms.Control In Controls
            If clsControl.Focused Then
                cntrl = clsControl
                Return clsControl

                Exit Function
            End If
            If clsControl.ContainsFocus Then
                If clsControl.Controls.Count = 0 Then
                    Return clsControl
                Else
                    Return GetFocusedControl(clsControl.Controls)
                End If
            End If
        Next
        ' no focus... 
        Return Nothing
    End Function

    Protected Overloads Overrides Sub OnMouseUp(ByVal e As System.Windows.Forms.MouseEventArgs)
        ' enable events... 
        MyBase.OnMouseUp(e)
        ' restore focus... 
        If m_clsFocusedControl IsNot Nothing Then
            m_clsFocusedControl.Focus()
            m_clsFocusedControl = Nothing
        Else
            Me.[Select]()
        End If
        ' gets rid of the drag rectangle... 
    End Sub

    Private m_clsFocusedControl As System.Windows.Forms.Control = Nothing

    Protected Overloads Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
        ' store focused control... 
        If e.Button = System.Windows.Forms.MouseButtons.Left Then
            m_clsFocusedControl = GetFocusedControl(Me.FindForm().Controls)
            m_clsFocusedControl = cntrl
            ' m_clsFocusedControl.Focus()
        End If
        ' enable events... 
        MyBase.OnMouseDown(e)
    End Sub

    Private Sub SplitContainer1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        OnMouseDown(e)
    End Sub

    Private Sub SplitContainer1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        OnMouseUp(e)
    End Sub

    Private Sub frmAddModifyInvestor_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        For lmFomrs As Integer = 0 To Application.OpenForms.Count - 1
            If Application.OpenForms(lmFomrs).Name = "frmInvestorManagement" Then
                RaiseEvent CloseUserWindow(_InvId)
                RemoveHandler CloseUserWindow, AddressOf CType(Application.OpenForms(lmFomrs), frmInvestorManagement).CloseUserWindow
                RemoveHandler AddParticularInvestorInGrid, AddressOf CType(Application.OpenForms(lmFomrs), frmInvestorManagement).AddParticularInvestorInGrid

            End If
        Next

        Me.Dispose(True)

    End Sub

    ''' <summary>
    ''' This will keep the selected investors on top and search for teh keyword will be at the botton of selected investors.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    ''' 

    Private Sub txtInvestorName_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs)
        'Auto Proper Implementation
        If (EnableProper(txtInvestorName.Text.Trim())) Then
            _IsProperInvestor = True
            Return
        End If
        _IsProperInvestor = False
        _IsProperInvestor = True
        txtInvestorName.Text = AutoProperConversion(txtInvestorName.Text.Trim())
        txtInvestorName.Focus()
        cmbMasterInvestorType.Focus()

        _IsProperInvestor = False
        '*******************************************************
    End Sub

    ''' <summary>
    ''' Method will set the back color for tab pages
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    ''' 


    Private Sub cmbHeadInvestor_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbHeadInvestor.SelectedIndexChanged
        If _IsUltimateParentChage = False Then
            Dim dsReturn As DataSet = Nothing
            Dim Id As String = String.Empty
            Dim HeadInvestor As String = String.Empty
            If cmbHeadInvestor.SelectedValue IsNot Nothing Then
                If cmbHeadInvestor.SelectedItem(0).ToString() = _NullField Then
                    MessageBox.Show("Please select valid Principal Investor", MessageManager.GetMessage("CRYSTAL"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    cmbHeadInvestor.SelectedValue = m_strSelectIDValue
                End If
            End If
            If cmbHeadInvestor.SelectedValue = m_strNewIDValue Then
                Dim objAddValue As New CrystalCommon.View.AddValue(enmEntityType.Source.ToString(), LKPMaster.HDINV, "Head Investor")
                objAddValue.ShowDialog()
                Id = objAddValue.ID
                If Id <> String.Empty Then
                    Dim obj As New BusinessLayer.cAddModifyInvestor
                    dsReturn = obj.GetHeadInvestorByID(Id)
                    If dsReturn IsNot Nothing Then
                        HeadInvestor = dsReturn.Tables(0).Rows(0)("HeadInvestor").ToString()
                        Id = dsReturn.Tables(0).Rows(0)("HeadInvestorID").ToString()
                        Dim table As DataTable = cmbHeadInvestor.DataSource
                        If table.Columns.Contains("HeadInvestorID") Then
                            Dim FilterQuery As String
                            Dim Excel() As DataRow
                            FilterQuery = "HeadInvestorID ='" + Trim(Id).Replace("'", "''") + "'"
                            Excel = table.Select(FilterQuery)
                            If Excel.Length = 0 Then
                                If DropDownAtLast(table, cmbHeadInvestor.ValueMember, cmbHeadInvestor.DisplayMember, Id, HeadInvestor) = False Then
                                    mdlCommon.ShowMessage("Error in accessing Header Investor drop down.", MessageBoxIcons.Error)
                                    Exit Sub
                                End If
                                cmbHeadInvestor.SelectedValue = Id
                            End If
                        End If
                    End If
                Else
                    cmbHeadInvestor.SelectedValue = m_strSelectIDValue
                End If
            End If
        End If

    End Sub

    Private Sub cmbActivist_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbActivist.SelectedIndexChanged
        Dim dsReturn As DataSet = Nothing
        Dim Id As String = String.Empty
        Dim Activist As String = String.Empty
        Try
            If cmbActivist.SelectedValue = m_strNewIDValue Then
                Dim objAddValue As New CrystalCommon.View.AddValue(enmEntityType.Source.ToString(), LKPMaster.ATVST, "Activist")
                objAddValue.ShowDialog()
                Id = objAddValue.ID
                If Id <> String.Empty Then
                    Dim obj As New BusinessLayer.cAddModifyInvestor
                    dsReturn = obj.GetActivistByID(Id)
                    If dsReturn IsNot Nothing Then
                        Activist = dsReturn.Tables(0).Rows(0)("Activist").ToString()
                        Id = dsReturn.Tables(0).Rows(0)("ActivistID").ToString()
                        Dim table As DataTable = cmbActivist.DataSource
                        If table.Columns.Contains("ActivistID") Then
                            Dim FilterQuery As String
                            Dim Excel() As DataRow
                            FilterQuery = "ActivistID ='" + Trim(Id).Replace("'", "''") + "'"
                            Excel = table.Select(FilterQuery)
                            If Excel.Length = 0 Then
                                If DropDownAtSecond(table, cmbActivist.ValueMember, cmbActivist.DisplayMember, Id, Activist) = False Then
                                    mdlCommon.ShowMessage("Error in accessing Header Investor drop down.", MessageBoxIcons.Error)
                                    Exit Sub
                                End If
                            End If
                            cmbActivist.SelectedValue = Id
                        End If
                    End If
                Else
                    cmbActivist.SelectedValue = m_strSelectIDValue
                End If

            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            Id = String.Empty
            Activist = String.Empty
        End Try
    End Sub

    Private Sub cmbInvestorType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbInvestorType.SelectedIndexChanged
        If istypeChanged = False Then
            Dim obj As New BusinessLayer.cAddModifyInvestor
            Dim dr As DataRow = Nothing
            Dim dt As New DataTable
            Dim idr As IDataReader = Nothing
            Dim dsReturn As DataSet = Nothing
            Dim Id As String = String.Empty
            Dim InvestorType As String = String.Empty
            Try
                If cmbInvestorType.SelectedValue = m_strNewIDValue Then
                    Dim objAddValue As New CrystalCommon.View.AddValue(enmEntityType.Source.ToString(), LKPMaster.INVTP, "Investor Type")
                    objAddValue.ShowDialog()
                    Id = objAddValue.ID
                    If Id <> String.Empty Then
                        dsReturn = obj.GetInvestorsByID(Id)
                        If dsReturn IsNot Nothing Then
                            InvestorType = dsReturn.Tables(0).Rows(0)("InvestorType").ToString()
                            Id = dsReturn.Tables(0).Rows(0)("InvestorTypeID").ToString()
                            Dim table As DataTable = cmbInvestorType.DataSource
                            If table.Columns.Contains("InvestorTypeID") Then
                                Dim FilterQuery As String
                                Dim Excel() As DataRow
                                FilterQuery = "InvestorTypeID ='" + Trim(Id).Replace("'", "''") + "'"
                                Excel = table.Select(FilterQuery)
                                If Excel.Length = 0 Then
                                    If DropDownAtSecond(table, cmbInvestorType.ValueMember, cmbInvestorType.DisplayMember, Id, InvestorType) = False Then
                                        mdlCommon.ShowMessage("Error in accessing Investor Type drop down.", MessageBoxIcons.Error)
                                        Exit Sub
                                    End If
                                End If
                                cmbInvestorType.SelectedValue = Id

                            End If
                        End If
                    Else
                        cmbInvestorType.SelectedValue = m_strSelectIDValue
                    End If

                Else
                    'If isFilling = False Then
                    If (Not cmbInvestorType.SelectedValue Is Nothing) Then
                        If cmbInvestorType.SelectedValue <> m_strSelectIDValue Then
                            idr = obj.MasterInvestorTypeByInvestorTypeId(cmbInvestorType.SelectedValue.ToString().Trim())
                            dt.Load(idr)
                            mdlCommon.ChangeDataReaderDataTable(dt)
                        Else
                            cmbMasterInvestorType.DataSource = Nothing
                            Exit Sub
                        End If

                    End If
                    If dt.Rows.Count > 0 Then
                        IsSelectedChanged = False
                        cmbMasterInvestorType.DisplayMember = "MInvestorType"
                        cmbMasterInvestorType.ValueMember = "MInvestorTypeID"
                        cmbMasterInvestorType.DataSource = dt
                        'If DropDownAtFirst(dt, cmbMasterInvestorType.ValueMember, cmbMasterInvestorType.DisplayMember, m_strNewIDValue, m_strNewTextValue) = False Then
                        '    mdlCommon.ShowMessage("Error in accessing Master Investor Type drop down.", MessageBoxIcons.Error)
                        '    Exit Sub
                        'End If
                        If InvestorId = 0 Then
                            If dt.Rows.Count = 1 Then
                                cmbMasterInvestorType.SelectedValue = dt.Rows(0)(1)
                                'Else
                                '    cmbMasterInvestorType.SelectedValue = m_strSelectIDValue
                            End If
                        Else
                            Dim dset As DataSet = cAddModifyInvestor.GetMasterInvestorID(InvestorId)
                            cmbMasterInvestorType.SelectedValue = dset.Tables(0).Rows(0)(0).ToString
                        End If
                        IsSelectedChanged = True
                    End If
                End If
                ' End If

            Catch ex As Exception
                MessageBox.Show(ex.Message)
            Finally
                obj = Nothing
                dr = Nothing
                dt = Nothing
            End Try
        End If
    End Sub

    Private Sub cmbStyle_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbStyle.SelectedIndexChanged
        Dim dsReturn As DataSet = Nothing
        Dim data As DataTable = Nothing
        Dim Id As String = String.Empty
        Dim Style As String = String.Empty
        Try
            If cmbStyle.SelectedValue = m_strNewIDValue Then
                Dim objAddValue As New CrystalCommon.View.AddValue(enmEntityType.Source.ToString(), LKPMaster.STYLE, "Style")
                objAddValue.ShowDialog()
                Id = objAddValue.ID
                If Id <> String.Empty Then
                    Dim obj As New BusinessLayer.cAddModifyInvestor
                    dsReturn = obj.GetStyleByID(Id)
                    If dsReturn IsNot Nothing Then
                        Style = dsReturn.Tables(0).Rows(0)("Style").ToString()
                        Id = dsReturn.Tables(0).Rows(0)("StyleID").ToString()
                        Dim table As DataTable = cmbStyle.DataSource
                        If table.Columns.Contains("StyleID") Then
                            Dim FilterQuery As String
                            Dim Excel() As DataRow
                            FilterQuery = "StyleID ='" + Trim(Id).Replace("'", "''") + "'"
                            Excel = table.Select(FilterQuery)
                            If Excel.Length = 0 Then
                                If DropDownAtSecond(table, cmbStyle.ValueMember, cmbStyle.DisplayMember, Id, Style) = False Then
                                    mdlCommon.ShowMessage("Error in accessing Style drop down.", MessageBoxIcons.Error)
                                    Exit Sub
                                End If
                            End If
                            cmbStyle.SelectedValue = Id
                        End If
                    End If
                Else
                    cmbStyle.SelectedValue = m_strSelectIDValue
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally

            Id = String.Empty
            Style = String.Empty
        End Try

    End Sub

    Private Sub cmbCity_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbCity.SelectedIndexChanged
        Dim dsReturn As DataSet = Nothing
        Dim data As DataTable = Nothing
        Dim Id As String = String.Empty
        Dim City As String = String.Empty
        Dim obj As New BusinessLayer.cAddModifyInvestor
        Try
            If cmbCity.SelectedValue = m_strNewIDValue Then
                Dim objAddValue As New CrystalCommon.View.AddValue(enmEntityType.Source.ToString(), LKPMaster.LCITY, "City")
                objAddValue.ParameterInt = cmbCountry.SelectedValue
                objAddValue.ShowDialog()
                If objAddValue.ID <> String.Empty Then
                    dsReturn = obj.GetTopCity()
                    If dsReturn IsNot Nothing Then
                        City = dsReturn.Tables(0).Rows(0)("City").ToString()
                        Id = dsReturn.Tables(0).Rows(0)("CityID").ToString()
                        Dim table As DataTable = cmbCity.DataSource
                        If table.Columns.Contains("CityID") Then
                            Dim FilterQuery As String
                            Dim Excel() As DataRow
                            FilterQuery = "CityID ='" + Trim(Id).Replace("'", "''") + "'"
                            Excel = table.Select(FilterQuery)
                            If Excel.Length = 0 Then
                                If DropDownAtLast(table, cmbCity.ValueMember, cmbCity.DisplayMember, Id, City) = False Then
                                    mdlCommon.ShowMessage("Error in accessing Investor Type drop down.", MessageBoxIcons.Error)
                                    Exit Sub
                                End If
                                cmbCity.SelectedValue = Id
                            End If
                        End If
                    End If
                Else
                    cmbCity.SelectedValue = m_strBlankIdValue
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Crystal", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            dsReturn = Nothing
            data = Nothing

        End Try
    End Sub


    Private Sub cmbCountry_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbCountryAD.SelectedIndexChanged, cmbCountry.SelectedIndexChanged

        Try
            If isCountryChanged = False Then

                Dim obj As New BusinessLayer.cAddModifyInvestor
                Dim Id As String = String.Empty
                Dim Country As String = String.Empty
                Dim dsReturn As DataSet = Nothing
                If cmbCountry.SelectedValue = m_strNewIDValue Then
                    Dim objAddValue As New CrystalCommon.View.AddValue(enmEntityType.Source.ToString(), LKPMaster.CNTRY, "Country")
                    objAddValue.ShowDialog()
                    Id = objAddValue.ID
                    If Id <> String.Empty Then

                        dsReturn = obj.GetCountryByID(Id)
                        If dsReturn IsNot Nothing Then
                            Country = dsReturn.Tables(0).Rows(0)("CountryName").ToString()
                            Id = dsReturn.Tables(0).Rows(0)("CountryID").ToString()
                            Dim table As DataTable = cmbState.DataSource
                            If table.Columns.Contains("CountryID") Then
                                Dim FilterQuery As String
                                Dim Excel() As DataRow
                                FilterQuery = "CountryID ='" + Trim(Id).Replace("'", "''") + "'"
                                Excel = table.Select(FilterQuery)
                                If Excel.Length = 0 Then
                                    If DropDownAtLast(table, cmbCountry.ValueMember, cmbCountry.DisplayMember, Id, Country) = False Then
                                        mdlCommon.ShowMessage("Error in accessing Country drop down.", MessageBoxIcons.Error)
                                        Exit Sub
                                    End If
                                    cmbCountry.SelectedValue = Id
                                End If
                            End If

                        End If
                    Else
                        cmbCountry.SelectedValue = m_strSelectIDValue
                    End If
                Else
                    If cmbCountry.SelectedValue <> Nothing And cmbCountry.SelectedValue <> m_strSelectIDValue Then
                        FillCityStateRegion()
                    End If

                End If
            End If

        Catch ex As Exception

        Finally
            'obj = Nothing
            'Id = String.Empty
            'Country = String.Empty
            'dsre = Nothing
        End Try
        ' End If

    End Sub


    Private Sub FillCityStateRegion()
        Dim obj As New BusinessLayer.cAddModifyInvestor
        Dim dr As DataRow = Nothing
        Dim dt As New DataTable
        Dim dtable As New DataTable
        Dim idr As IDataReader = Nothing
        Dim dset As DataSet = Nothing
        Dim drv As DataRowView = cmbCountry.SelectedItem
        Try
            'cmbState.Enabled = False
            cmbCity.Enabled = True
            IsSelectedChanged = False
            dset = cAddModifyInvestor.GetStateCodeNCityByCountryID(cmbCountry.SelectedValue)
            cmbCity.DisplayMember = "City"
            cmbCity.ValueMember = "CityID"
            dt = dset.Tables(1)
            cmbCity.DataSource = dt
            If DropDownAtFirst(dt, cmbCity.ValueMember, cmbCity.DisplayMember, m_strNewIDValue, m_strNewTextValue) = False Then
                mdlCommon.ShowMessage("Error in accessing City drop down.", MessageBoxIcons.Error)
                Exit Sub
            End If
            cmbCity.SelectedValue = m_strSelectIDValue
            If cmbCity.Items.Count > 0 Then
                RequiredValidateControl(cmbCity, "City")
            Else
                RemoveRequiredValidation(cmbCity, "City")
            End If
            '''''''''''''''''''''''''''''''''''State..........................
            If (cmbCountry.Text.ToLower().Contains("united states") = True Or cmbCountry.Text.ToString().ToLower().Contains("canada")) Then
                cmbState.Enabled = True
                cmbState.DisplayMember = "State"
                cmbState.ValueMember = "StateID"
                dtable = dset.Tables(0)
                cmbState.DataSource = dtable
                'If DropDownAtFirst(dtable, cmbState.ValueMember, cmbState.DisplayMember, m_strNewIDValue, m_strNewTextValue) = False Then
                '    mdlCommon.ShowMessage("Error in accessing State drop down.", MessageBoxIcons.Error)
                '    Exit Sub
                'End If
                cmbState.SelectedValue = m_strSelectIDValue
                RequiredValidateControl(cmbState, "State")
                '''''''''''''''''''''''''''''''''''''''City..........................

            Else
                cmbState.Enabled = False
                RemoveRequiredValidation(cmbState, "State")
                cmbState.SelectedValue = m_strSelectIDValue
            End If
            If (InvestorId <> 0) Then
                Dim da As DataSet = cAddModifyInvestor.GetCityNStateByInvID(InvestorId)
                If (da.Tables(0).Rows.Count > 0) Then
                    If Not da.Tables(0).Rows(0)(0).ToString() = String.Empty Then
                        cmbCity.SelectedValue = da.Tables(0).Rows(0)(0)
                    End If
                    If cmbState.Enabled Then
                        If Not da.Tables(0).Rows(0)(1).ToString() = String.Empty Then
                            cmbState.SelectedValue = da.Tables(0).Rows(0)(1)
                        End If
                    End If
                End If
            End If

            If cmbCountry.SelectedValue <> Nothing And cmbCountry.SelectedValue > 0 Then
                Dim dataSet As DataSet = obj.GetRegionForCountry(cmbCountry.SelectedValue)
                If dataSet.Tables(0).Rows.Count > 0 Then
                    txtRegion.Text = dataSet.Tables(0).Rows(0)(0).ToString()
                End If
            Else
                txtRegion.Text = String.Empty
            End If
            If cmbCountry.SelectedValue = m_strSelectIDValue Then
                txtRegion.Text = ""
            End If
            IsSelectedChanged = True
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            obj = Nothing
            dr = Nothing
            dt = Nothing
            dset = Nothing
        End Try
    End Sub

#End Region

#Region "Combo selected value changed"

    Private Sub cmbUltimateParent_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbUltimateParent.SelectedIndexChanged
        If IsLoading = False Then
            'If isChangeUltimateParent = False Then
            If isInsertProcess = False Then
                '    If IsSelectedChanged = True Then
                Dim dsReturn As DataSet = Nothing
                Dim UltimateParent As String = String.Empty
                Dim Id As String = String.Empty
                If cmbUltimateParent.SelectedValue = m_strNewIDValue Then
                    Dim objAddValue As New CrystalCommon.View.AddValue(enmEntityType.Source.ToString(), LKPMaster.UPRNT, "Ultimate Parent")
                    objAddValue.ShowDialog()
                    Id = objAddValue.ID
                    If Id <> String.Empty Then
                        Dim obj As New BusinessLayer.cAddModifyInvestor
                        dsReturn = obj.GetUltimateParentByID(Id)
                        If dsReturn IsNot Nothing Then
                            UltimateParent = dsReturn.Tables(0).Rows(0)("UltimateParent").ToString()
                            Id = dsReturn.Tables(0).Rows(0)("UltimateParentID").ToString()
                            Dim table As DataTable = cmbUltimateParent.DataSource
                            If table.Columns.Contains("UltimateParentID") Then
                                Dim FilterQuery As String
                                Dim Excel() As DataRow
                                FilterQuery = "UltimateParentID ='" + Trim(Id).Replace("'", "''") + "'"
                                Excel = table.Select(FilterQuery)
                                If Excel.Length = 0 Then
                                    If DropDownAtSecond(table, cmbUltimateParent.ValueMember, cmbUltimateParent.DisplayMember, Id, UltimateParent) = False Then
                                        mdlCommon.ShowMessage("Error in accessing Country drop down.", MessageBoxIcons.Error)
                                        Exit Sub
                                    End If
                                End If
                                cmbUltimateParent.SelectedValue = Id
                            End If
                        End If
                    Else
                        cmbUltimateParent.SelectedValue = m_strSelectIDValue
                    End If

                Else
                    Dim table As DataTable = cmbHeadInvestor.DataSource
                    Dim selectedValues As String = String.Empty

                    If cmbHeadInvestor.SelectedValue IsNot Nothing And cmbHeadInvestor.SelectedValue <> m_strSelectIDValue Then
                        Dim selectedPI As DataRowView = cmbHeadInvestor.SelectedItem
                        selectedValues = selectedPI.Row.ItemArray.GetValue(1)
                    End If
                    If cmbUltimateParent.SelectedValue IsNot Nothing Then
                        If cmbUltimateParent.SelectedValue <> m_strSelectIDValue Then
                            Dim d As DataRowView = cmbUltimateParent.SelectedItem
                            Dim str As String = d.Row.ItemArray.GetValue(0)
                            If str <> txtInvestorName.Text Then

                                If table.Columns.Contains("HeadInvestorID") Then
                                    Dim FilterQuery As String
                                    Dim Excel() As DataRow
                                    FilterQuery = "HeadInvestorID ='" + Trim(UltimateInPriInv).Replace("'", "''") + "'"
                                    Excel = table.Select(FilterQuery)
                                    If Excel.Length = 1 Then
                                        'Excel.First().Item(0) = cmbUltimateParent.Text
                                        _IsUltimateParentChage = True
                                        table.Rows().Remove(Excel.First())
                                        _IsUltimateParentChage = False
                                    End If
                                End If
                                ' End If
                                If txtInvestorName.Text.Length = 0 Then
                                    If DropDownAtSecond(table, "HeadInvestorID", "Head Investor", UltimateInPriInv, str) = False Then
                                        mdlCommon.ShowMessage("Error in accessing Head Investor drop down.", MessageBoxIcons.Error)
                                        Exit Sub
                                    End If
                                    AddNullContainer(table)
                                Else
                                    If DropDownAtThird(table, "HeadInvestorID", "Head Investor", UltimateInPriInv, str) = False Then
                                        mdlCommon.ShowMessage("Error in accessing Head Investor drop down.", MessageBoxIcons.Error)
                                        Exit Sub
                                    End If
                                End If
                                If txtInvestorName.Text.Length = 0 Then
                                    cmbHeadInvestor.SelectedValue = m_strSelectIDValue
                                Else
                                    cmbHeadInvestor.SelectedValue = selectedValues
                                End If
                                ' AddUltimateParentToPrincipalInv()
                            Else
                                If table.Columns.Contains("HeadInvestorID") Then
                                    Dim FilterQuery As String
                                    Dim Excel() As DataRow
                                    FilterQuery = "HeadInvestorID ='" + Trim(UltimateInPriInv).Replace("'", "''") + "'"
                                    Excel = table.Select(FilterQuery)
                                    If Excel.Length = 1 Then
                                        table.Rows().Remove(Excel.First())
                                    End If
                                End If
                            End If
                        End If
                    End If

                End If
            End If

        End If

    End Sub
    Private Sub AddUltimateParentToPrincipalInv()
        Dim table As DataTable = cmbHeadInvestor.DataSource
        If cmbUltimateParent.SelectedItem IsNot Nothing Then
            Dim d As DataRowView = cmbUltimateParent.SelectedItem
            Dim str As String = d.Row.ItemArray.GetValue(0)
            Dim value As String = cmbHeadInvestor.SelectedValue
            If DropDownAtThird(table, "HeadInvestorID", "Head Investor", -8, str) = False Then
                mdlCommon.ShowMessage("Error in accessing Head Investor drop down.", MessageBoxIcons.Error)
                Exit Sub
            End If
        End If

    End Sub

    Private Sub cmbParent_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbParent.SelectedIndexChanged
        Dim dsReturn As DataSet = Nothing
        Dim Id As String = String.Empty
        Dim Parent As String = String.Empty
        If cmbParent.SelectedValue = m_strNewIDValue Then
            Dim objAddValue As New CrystalCommon.View.AddValue(enmEntityType.Source.ToString(), LKPMaster.PRENT, "Parent")
            objAddValue.ShowDialog()
            Id = objAddValue.ID
            If Id <> String.Empty Then
                Dim obj As New BusinessLayer.cAddModifyInvestor
                dsReturn = obj.GetParentByID(Id)
                If dsReturn IsNot Nothing Then
                    Parent = dsReturn.Tables(0).Rows(0)("Parent").ToString()
                    Id = dsReturn.Tables(0).Rows(0)("ParentID").ToString()
                    Dim table As DataTable = cmbParent.DataSource
                    If table.Columns.Contains("ParentID") Then
                        Dim FilterQuery As String
                        Dim Excel() As DataRow
                        FilterQuery = "ParentID ='" + Trim(Id).Replace("'", "''") + "'"
                        Excel = table.Select(FilterQuery)
                        If Excel.Length = 0 Then
                            If DropDownAtSecond(table, cmbParent.ValueMember, cmbParent.DisplayMember, Id, Parent) = False Then
                                mdlCommon.ShowMessage("Error in accessing Country drop down.", MessageBoxIcons.Error)
                                Exit Sub
                            End If
                        End If
                        cmbParent.SelectedValue = Id
                    End If
                End If
            Else
                cmbParent.SelectedValue = m_strSelectIDValue
            End If

        End If
    End Sub

#End Region


    'Private Sub txtCMobLocalNumber_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCMobLocalNumber.Enter
    '    If Not txtCMobLocalNumber.Text.Contains("+") Then
    '        txtCMobLocalNumber.Text = "+" + txtCMobLocalNumber.Text
    '    End If

    'End Sub

    'Private Sub txtCTelLocalNumber_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCTelLocalNumber.Enter
    '    If Not txtCTelLocalNumber.Text.Contains("+") Then
    '        txtCTelLocalNumber.Text = "+" + txtCTelLocalNumber.Text
    '    End If
    'End Sub

    'Private Sub txtCPFLocalNumber_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCPFLocalNumber.Enter
    '    If Not txtCPFLocalNumber.Text.Contains("+") Then
    '        txtCPFLocalNumber.Text = "+" + txtCPFLocalNumber.Text
    '    End If
    'End Sub

    'Private Sub txtCAFLocalNumber_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCAFLocalNumber.Enter
    '    If Not txtCAFLocalNumber.Text.Contains("+") Then
    '        txtCAFLocalNumber.Text = "+" + txtCAFLocalNumber.Text
    '    End If
    'End Sub

    Private Sub txtCMobLocalNumber_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCMobLocalNumber.Leave
        If txtCMobLocalNumber.Text.Length > 0 Then

            If Not txtCMobLocalNumber.Text.Contains("+") Then
                txtCMobLocalNumber.Text = "+" + txtCMobLocalNumber.Text
            End If
        End If

    End Sub

    Private Sub txtCTelLocalNumber_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCTelLocalNumber.Leave
        If txtCTelLocalNumber.Text.Length > 0 Then

            If Not txtCTelLocalNumber.Text.Contains("+") Then
                txtCTelLocalNumber.Text = "+" + txtCTelLocalNumber.Text
            End If
        End If

    End Sub

    Private Sub txtCPFLocalNumber_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCPFLocalNumber.Leave
        If txtCPFLocalNumber.Text.Length > 0 Then

            If Not txtCPFLocalNumber.Text.Contains("+") Then
                txtCPFLocalNumber.Text = "+" + txtCPFLocalNumber.Text
            End If
        End If

    End Sub

    Private Sub txtCAFLocalNumber_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCAFLocalNumber.Leave
        If txtCAFLocalNumber.Text.Length > 0 Then

            If Not txtCAFLocalNumber.Text.Contains("+") Then
                txtCAFLocalNumber.Text = "+" + txtCAFLocalNumber.Text
            End If
        End If

    End Sub

    Private Sub rdExtinct_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdExtinct.CheckedChanged
        If rdExtinct.Checked Then
            If isFilling = False Then
                ShowMessage("Marking an investor as Extinct will prevent it from being used anywhere in the application.")
            End If
        End If
    End Sub

    Private Sub rdDelete_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdDelete.CheckedChanged
        If rdDelete.Checked Then
            If isFilling = False Then
                ShowMessage("The following investor have been marked as delete. Once all references to this investor in projects have been removed, the investor will be deleted automatically.")
            End If
        End If
    End Sub


    Private Sub txtInvestorName_Leave1(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtInvestorName.Leave
        Dim selected As Boolean = False
        isInsertProcess = True
        '  If InvestorId = 0 Then
        If txtInvestorName.Text.Length > 0 Then
            UpdateHeadInvestor(txtInvestorName.Text)
            If cmbUltimateParent.SelectedValue = Nothing Or cmbUltimateParent.SelectedValue = m_strSelectIDValue Then
                selected = True
            End If
            isInsertProcess = True

            UpdateUltimatePrincipalInvestor(txtInvestorName.Text)
            If selected Then
                cmbUltimateParent.SelectedValue = m_strSelectIDValue
            End If
        End If
    End Sub

    Private Sub UpdateUltimatePrincipalInvestor(ByVal UltimateParent As String)


        Dim Id As Int32 = cAddModifyInvestor.GetMaxUltimateParentID()
        Dim table As DataTable = cmbUltimateParent.DataSource
        isInsertProcess = True
        If table.Columns.Contains("UltimateParentID") Then
            Dim FilterQuery As String
            Dim Excel() As DataRow
            FilterQuery = "UltimateParentID ='" + Trim(Id + 1).Replace("'", "''") + "'"
            Excel = table.Select(FilterQuery)
            If Excel.Length = 0 Then
                If DropDownAtSecond(table, cmbUltimateParent.ValueMember, cmbUltimateParent.DisplayMember, Id + 1, UltimateParent) = False Then
                    mdlCommon.ShowMessage("Error in accessing UltimateParent Investor drop down.", MessageBoxIcons.Error)
                    Exit Sub
                End If
            Else
                table.Rows().Remove(Excel.First())
                If DropDownAtSecond(table, cmbUltimateParent.ValueMember, cmbUltimateParent.DisplayMember, Id + 1, UltimateParent) = False Then
                    mdlCommon.ShowMessage("Error in accessing Ultimate Parent drop down.", MessageBoxIcons.Error)
                    Exit Sub
                End If
            End If
            isInsertProcess = False
        End If


    End Sub

    Private Sub UpdateHeadInvestor(ByVal HeadInvestor As String)
        Dim Id As Int32 = cAddModifyInvestor.GetMaxHeadInvestorID()
        Dim table As DataTable = cmbHeadInvestor.DataSource
        If table.Columns.Contains("HeadInvestorID") Then
            Dim FilterQuery As String
            Dim Excel() As DataRow
            FilterQuery = "HeadInvestorID ='" + Trim(Id + 1).Replace("'", "''") + "'"
            Excel = table.Select(FilterQuery)
            If Excel.Length = 0 Then
                If DropDownAtSecond(table, cmbHeadInvestor.ValueMember, cmbHeadInvestor.DisplayMember, Id + 1, HeadInvestor) = False Then
                    mdlCommon.ShowMessage("Error in accessing Head Investor drop down.", MessageBoxIcons.Error)
                    Exit Sub
                End If
            Else
                table.Rows().Remove(Excel.First())
                If DropDownAtSecond(table, cmbHeadInvestor.ValueMember, cmbHeadInvestor.DisplayMember, Id + 1, HeadInvestor) = False Then
                    mdlCommon.ShowMessage("Error in accessing Head Investor drop down.", MessageBoxIcons.Error)
                    Exit Sub
                End If
            End If
            AddNullContainer(table)
        End If
        cmbHeadInvestor.SelectedValue = Id + 1
    End Sub
    Private Sub AddNullContainer(ByVal table As DataTable)
        If table.Columns.Contains("HeadInvestorID") Then
            Dim FilterQuery As String
            Dim Excel() As DataRow
            FilterQuery = "HeadInvestorID ='" + Trim(_NullID).Replace("'", "''") + "'"
            Excel = table.Select(FilterQuery)
            If Excel.Length = 0 Then
                If DropDownAtThird(table, cmbHeadInvestor.ValueMember, cmbHeadInvestor.DisplayMember, _NullID, _NullField) = False Then
                    mdlCommon.ShowMessage("Error in accessing Head Investor drop down.", MessageBoxIcons.Error)
                    Exit Sub
                End If
            End If
        End If
    End Sub
    Private Sub cmbHeadInvestor_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)

        Dim objListBox As ComboBox = cmbHeadInvestor
        Dim itemIndex As Integer = -1
        Dim arr As DataTable = cmbHeadInvestor.DataSource
        If arr IsNot Nothing Then
            If objListBox.ItemHeight <> 0 Then
                itemIndex = e.Y / objListBox.ItemHeight
                itemIndex += objListBox.Top
            End If
            'objListBox.Items().Item.itemIndex = ListBox1.ItemAtPos(Point(x, y), True)
            ToolTip1.SetToolTip(objListBox, cmbHeadInvestor.GetItemText(itemIndex)) '(objListBox.Items().Item.itemIndex))
            'ToolTip1.Hide(objListBox)e.

        End If
    End Sub


    Private Sub cmbHeadInvestor_DropdownItemSelected1(ByVal sender As Object, ByVal e As ComboToolTip.DropdownItemSelectedEventArgs) Handles cmbHeadInvestor.DropdownItemSelected
        If (e.SelectedItem < 0 Or e.Scrolled) Then
            ToolTip1.Hide(cmbHeadInvestor)
        Else
            ToolTip1.Hide(cmbHeadInvestor)
            Dim textWidth As Integer = cmbHeadInvestor.Items(e.SelectedItem)(0).ToString().Length
            If textWidth > 50 Then
                ToolTip1.Show(cmbHeadInvestor.Items(e.SelectedItem)(0).ToString(), cmbHeadInvestor, e.Bounds.Location)
            End If
        End If
    End Sub

    Private Sub cmbParent_DropdownItemSelected(ByVal sender As System.Object, ByVal e As Crystal.CustomControls.ComboToolTip.DropdownItemSelectedEventArgs) Handles cmbParent.DropdownItemSelected
        If (e.SelectedItem < 0 Or e.Scrolled) Then
            ToolTip1.Hide(cmbParent)
        Else
            ToolTip1.Hide(cmbParent)
            Dim textWidth As Integer = cmbParent.Items(e.SelectedItem)(0).ToString().Length
            If textWidth > 30 Then
                ToolTip1.Show(cmbParent.Items(e.SelectedItem)(0).ToString(), cmbParent, e.Bounds.Location)
            End If
        End If
    End Sub

    Private Sub cmbUltimateParent_DropdownItemSelected(ByVal sender As System.Object, ByVal e As Crystal.CustomControls.ComboToolTip.DropdownItemSelectedEventArgs) Handles cmbUltimateParent.DropdownItemSelected
        If (e.SelectedItem < 0 Or e.Scrolled) Then
            ToolTip1.Hide(cmbUltimateParent)
        Else
            ToolTip1.Hide(cmbUltimateParent)
            Dim textWidth As Integer = cmbUltimateParent.Items(e.SelectedItem)(0).ToString().Length
            If textWidth > 30 Then
                ToolTip1.Show(cmbUltimateParent.Items(e.SelectedItem)(0).ToString(), cmbUltimateParent, e.Bounds.Location)
            End If
        End If
    End Sub

    Private Sub cmbMasterInvestorType_DropdownItemSelected(ByVal sender As System.Object, ByVal e As Crystal.CustomControls.ComboToolTip.DropdownItemSelectedEventArgs) Handles cmbMasterInvestorType.DropdownItemSelected
        If (e.SelectedItem < 0 Or e.Scrolled) Then
            ToolTip1.Hide(cmbMasterInvestorType)
        Else
            ToolTip1.Hide(cmbMasterInvestorType)
            Dim textWidth As Integer = cmbMasterInvestorType.Items(e.SelectedItem)(0).ToString().Length
            If textWidth > 30 Then
                ToolTip1.Show(cmbMasterInvestorType.Items(e.SelectedItem)(0).ToString(), cmbMasterInvestorType, e.Bounds.Location)
            End If
        End If
    End Sub

    Private Sub cmbInvestorType_DropdownItemSelected(ByVal sender As System.Object, ByVal e As Crystal.CustomControls.ComboToolTip.DropdownItemSelectedEventArgs) Handles cmbInvestorType.DropdownItemSelected

    End Sub

    Private Sub cmbStyle_DropdownItemSelected(ByVal sender As System.Object, ByVal e As Crystal.CustomControls.ComboToolTip.DropdownItemSelectedEventArgs) Handles cmbStyle.DropdownItemSelected

    End Sub

    Private Sub cmbTurnoverLabel_DropdownItemSelected(ByVal sender As System.Object, ByVal e As Crystal.CustomControls.ComboToolTip.DropdownItemSelectedEventArgs) Handles cmbTurnoverLabel.DropdownItemSelected

    End Sub

    Private Sub cmbCountry_DropdownItemSelected(ByVal sender As System.Object, ByVal e As Crystal.CustomControls.ComboToolTip.DropdownItemSelectedEventArgs) Handles cmbCountry.DropdownItemSelected
        If (e.SelectedItem < 0 Or e.Scrolled) Then
            ToolTip1.Hide(cmbCountry)
        Else
            ToolTip1.Hide(cmbCountry)
            Dim textWidth As Integer = cmbCountry.Items(e.SelectedItem)(0).ToString().Length
            If textWidth > 50 Then
                ToolTip1.Show(cmbCountry.Items(e.SelectedItem)(0).ToString(), cmbCountry, e.Bounds.Location)
            End If
        End If
    End Sub

    Private Sub cmbCity_DropdownItemSelected(ByVal sender As System.Object, ByVal e As Crystal.CustomControls.ComboToolTip.DropdownItemSelectedEventArgs) Handles cmbCity.DropdownItemSelected
        If (e.SelectedItem < 0 Or e.Scrolled) Then
            ToolTip1.Hide(cmbCity)
        Else
            ToolTip1.Hide(cmbCity)
            Dim textWidth As Integer = cmbCity.Items(e.SelectedItem)(0).ToString().Length
            If textWidth > 30 Then
                ToolTip1.Show(cmbCity.Items(e.SelectedItem)(0).ToString(), cmbCity, e.Bounds.Location)
            End If
        End If
    End Sub

    Private Sub cmbCountryAD_DropdownItemSelected(ByVal sender As System.Object, ByVal e As Crystal.CustomControls.ComboToolTip.DropdownItemSelectedEventArgs) Handles cmbCountryAD.DropdownItemSelected
        If (e.SelectedItem < 0 Or e.Scrolled) Then
            ToolTip1.Hide(cmbCountryAD)
        Else
            ToolTip1.Hide(cmbCountryAD)
            Dim textWidth As Integer = cmbCountryAD.Items(e.SelectedItem)(0).ToString().Length
            If textWidth > 30 Then
                ToolTip1.Show(cmbCountryAD.Items(e.SelectedItem)(0).ToString(), cmbCountryAD, e.Bounds.Location)
            End If
        End If
    End Sub

    Private Sub txtInvestorName_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtInvestorName.Enter
        preUltimateParent = txtInvestorName.Text
    End Sub

    Private Sub llblWebsite_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles llblWebsite.LinkClicked
        'llblWebsite.Links.Add(llblWebsite)
    End Sub


    Private Sub grdInvestors_MouseClick1(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles grdInvestors.MouseClick
        Dim grid As UltraGrid = sender
        Dim controlelement As Infragistics.Win.UIElement = grid.DisplayLayout.UIElement
        Dim elementAtPoint As Infragistics.Win.UIElement = If(controlelement IsNot Nothing, controlelement.ElementFromPoint(e.Location), Nothing)
        Dim column As UltraGridColumn = Nothing
        While elementAtPoint IsNot Nothing
            Dim headerElement As HeaderUIElement = TryCast(elementAtPoint, HeaderUIElement)
            If headerElement IsNot Nothing AndAlso TypeOf headerElement.Header Is Infragistics.Win.UltraWinGrid.ColumnHeader Then
                column = TryCast(headerElement.GetContext(GetType(UltraGridColumn)), UltraGridColumn)
                Exit While
            End If
            elementAtPoint = elementAtPoint.Parent
        End While
        If column IsNot Nothing Then

            Dim data As DataTable = grdInvestors.DataSource
            Dim investorLink As New AddFundInvLink
            investorLink.dtLinked = data
            investorLink.Text = "Investor Fund Link"
            investorLink.ShowDialog()
            If investorLink.dtLinked IsNot Nothing Then
                data.Merge(investorLink.dtLinked, True, MissingSchemaAction.Ignore)
                _PerDataTable.Merge(investorLink.dtLinked, True, MissingSchemaAction.Ignore)
                grdInvestors.DataSource = data
                mdtLinkedFunds = investorLink.dtLinked
                _IsInvFundLinked = True
            End If
            investorLink = Nothing
        End If
    End Sub

    Private Sub txtequityAssets_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
        Try
            If (e.KeyChar.ToString() = ".") Then
                e.Handled = True
                Return
            End If
            Dim st As String
            If Clipboard.ContainsText() Then
                st = Clipboard.GetText()
                If (Validations.CheckNumericString(st) = False) Then
                    e.Handled = True
                    Clipboard.Clear()
                Else
                    e.Handled = False
                End If
            Else
                If (Validations.CheckNumeric(e.KeyChar) = False) Then
                    e.Handled = True
                Else
                    e.Handled = False
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally

        End Try
    End Sub

    Private Sub txtequityAssets_KeyPress2(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtequityAssets.KeyPress
        Try
            Dim st As String
            'KeyPressIndex = txtSharesIssue.
            CheckValueChange = True
            If (e.KeyChar.ToString() = "." Or e.KeyChar.ToString() = "-") Then
                e.Handled = True
                Return
            End If
            If Clipboard.ContainsText() Then
                st = Clipboard.GetText()
                If (Validations.CheckNumericString(st) = False) Then
                    e.Handled = True
                    Clipboard.Clear()
                Else
                    e.Handled = False
                End If
            Else

                If (Validations.CheckNumeric(e.KeyChar) = False) Then
                    e.Handled = True
                Else
                    e.Handled = False
                End If
            End If
            CheckValueChange = False

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally

        End Try
    End Sub

    Private Sub txtequityAssets_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtequityAssets.TextChanged
        If txtequityAssets.Text = String.Empty Then Exit Sub
        If CheckValueChange = False Then
            Dim value As Int64
            Dim stringValue As String = txtequityAssets.Text
            stringValue = stringValue.Replace(",", "")
            Dim isbool As Boolean = False
            isbool = Int64.TryParse(stringValue, value)
            If isbool Then
                stringValue = value.ToString("#,##0")
            End If
            CheckValueChange = True
            txtequityAssets.Text = stringValue
            CheckValueChange = False
            'txtSharesIssue.Update()
            txtequityAssets.SelectionStart = txtequityAssets.Text.Length
        End If
    End Sub
End Class